Oracle Certification, Database Administration, SQL, Application, Programming Reference Books
TEXT_IO code to write data to a flat file

PROCEDURE CREATE_FLAT_FILE IS
-- DESCRIPTION
--  Simple procedure to write to a text fille from a form
-- NOTES
--      Call this procedure from the WHEN-BBUTTON-PRESSED trigger
-- REQUIREMENTS
--  Must have access to local drives
--
--=============================================================================

   in_file   TEXT_IO.FILE_TYPE;
   linebuf   VARCHAR2(80);
   your_file VARCHAR2(50) := 'C:\TEMP\your_file.dat';
   text_line VARCHAR2(400);
BEGIN
    in_file := TEXT_IO.FOPEN(your_file, 'W');
    GO_BLOCK('YOUR_DATA_BLOCK');
    FIRST_RECORD;
    LOOP
 IF :your_checkbox = 'Y' THEN
  text_line := LPAD(:your_item1, 10, ' ')||
      LPAD(:your_item2, 20, ' ')||
           LPAD(:your_item3, 30, ' ')||
                LPAD(:your_item4, 50, ' ');
     --

          TEXT_IO.PUT_LINE(in_file, text_line);
      END IF;
          --
      exit when :SYSTEM.LAST_RECORD = 'TRUE';
      NEXT_RECORD;
    END LOOP;
    --
    TEXT_IO.FCLOSE(in_file);
EXCEPTION
     WHEN NO_DATA_FOUND THEN
      TEXT_IO.FCLOSE(in_file);
END;
 

Return to : Oracle Database, SQL, Application, Programming Tips