top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Can one read/write files from PL/SQL?

+1 vote
273 views
Can one read/write files from PL/SQL?
posted Nov 26, 2014 by Suchithra

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

In Oracle 7.3 is an UTL_FILE package that can read and write operating system files. The directory you intend writing to has to be in your INIT.ORA file (see UTL_FILE_DIR=... parameter). Before Oracle 7.3 the only means of writing a file was to use DBMS_OUTPUT with the SQL*Plus SPOOL command.
Copy this example to get started:

DECLARE
  fileHandler UTL_FILE.FILE_TYPE;
BEGIN
  fileHandler := UTL_FILE.FOPEN('/tmp', 'myfile', 'w');
  UTL_FILE.PUTF(fileHandler, 'Look ma, I''m writing to a file!!!n');
  UTL_FILE.FCLOSE(fileHandler);
EXCEPTION
  WHEN utl_file.invalid_path THEN
     raise_application_error(-20000, 'ERROR: Invalid path for file or path not in INIT.ORA.');
END;
/
answer Nov 28, 2014 by Manikandan J
...