2

I am testing the following code in TOAD.


create directory test_dir AS 'c:\';
DECLARE
  fileHandler UTL_FILE.FILE_TYPE;
BEGIN
  fileHandler := UTL_FILE.FOPEN('test_dir', 'test_file.txt', 'W');
  UTL_FILE.PUTF(fileHandler, 'Test 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.');
END;  

It returns the following error:

Error at line 1
ORA-20000: ERROR: Invalid PATH FOR file.
ORA-06512: at line 9

Could anyone tell me how to resolve this error? Thanks so much!

ohnycany
  • 67
  • 5
  • 1
    Change `'test_dir'` to `'TEST_DIR'`. See duplicate question: https://stackoverflow.com/questions/40873133/invalid-path-while-trying-to-write-the-file-in-pl-sql – kfinity Dec 03 '19 at 17:18
  • Does this answer your question? [invalid path while trying to write the file in pl sql](https://stackoverflow.com/questions/40873133/invalid-path-while-trying-to-write-the-file-in-pl-sql) – Popeye Dec 03 '19 at 17:26
  • Tried 'TEST_DIR' but it still didn't work. Could the error be caused by the fact that the database is on a separate server? – ohnycany Dec 03 '19 at 17:29
  • Yes - UTL_FILE reads/writes files on the database server. If you want to write to a file on your client computer, it depends on your SQL client - SQL*Plus uses SPOOL, others have wizards to save different kinds of files. – kfinity Dec 03 '19 at 18:21

0 Answers0