How to create a File in OS

 How to create a File in OS using UTL.FILE


CREATE OR REPLACE DIRECTORY my_dir AS '/path/to/your/folder';


GRANT READ, WRITE ON DIRECTORY my_dir TO MY_USER;


DECLARE
  l_file UTL_FILE.FILE_TYPE;
BEGIN
  l_file := UTL_FILE.FOPEN('MY_DIR', 'test_output.txt', 'W');
  UTL_FILE.PUT_LINE(l_file, 'This is a test file created by MY_USER.');
  UTL_FILE.FCLOSE(l_file);
  DBMS_OUTPUT.PUT_LINE('File created successfully.');
EXCEPTION
  WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('Error: ' || SQLCODE || ' - ' || SQLERRM);
END;
/


Check file in your directory by the name of my_dir

Comments