Adsense Ad

Tuesday 6 August 2019

Oracle Forms: Check / Create / Read File using text_IO

--Create File
Declare
  l_Out_File Text_Io.File_Type;
  l_In_File  Text_Io.File_Type;
  Linelog    Varchar2(32767);
Begin
  l_Out_File := Text_Io.Fopen('Text.txt', 'a'); -- w is write, r is read, a is append
  Text_Io.Put_Line(l_Out_File,
                   To_Char(Sysdate, 'dd-mon-rrrr hh24miss');
  Text_Io.Fclose(l_Out_File);
Exception
  When Others Then
    If Sqlcode = -302000 Then
      -- file problems
      Message('SystemError: File not found.');
      Message('SystemError: File not found.');
      Raise Form_Trigger_Failure;
    Else
      -- other problems
      Message('LogicError: ' || Sqlerrm);
      Message('LogicError: ' || Sqlerrm);
      Raise Form_Trigger_Failure;
    End If;
End;


--------------------------------------------------------------------


--Read File
Declare
  l_In_File Text_Io.File_Type;
  Linelog   Varchar2(32767);
Begin
  l_In_File := Text_Io.Fopen('Text.txt', 'r'); -- w is write, r is read, a is append
  Begin
    Loop
      Text_Io.Get_Line(l_In_File, Linelog);
    End Loop;
  Exception
    When Others Then
      Text_Io.Fclose(l_In_File);
  End;
  Message(Linelog);
  Message(Linelog);
Exception
  When Others Then
    If Sqlcode = -302000 Then
      -- file problems
      Message('SystemError: File not found.');
      Message('SystemError: File not found.');
      Raise Form_Trigger_Failure;
    Else
      -- other problems
      Message('LogicError: ' || Sqlerrm);
      Message('LogicError: ' || Sqlerrm);
      Raise Form_Trigger_Failure;
    End If;

End;

No comments: