How to write a text file from Pl / SQL, error PLS 00363

I am trying to write a file from a procedure:

out_File := Utl_File.FOpen('C:\test', 'batotest.txt' , 'W'); Utl_File.Put_Line(out_file , 'Hi this is text file!'); Utl_File.FClose(out_file); 

Compilation errors for PACKAGE xxxxxxxx

 Error: PLS-00363: âûðàæåíèå 'OUT_FILE' íå ì.á. èñïîëüçîâàíî êàê àäðåñàò íàçíà÷åíèÿ Line: 795 Text: out_File := Utl_File.FOpen('C:\test', 'batotest.txt' , 'W'); Error: PL/SQL: Statement ignored Line: 795 Text: out_File := Utl_File.FOpen('C:\test', 'batotest.txt' , 'W'); Error: PLS-00363: 'OUT_FILE' íå ì.á. èñïîëüçîâàíî êàê àäðåñàò íàçíà÷åíèÿ Line: 797 Text: Utl_File.FClose(out_file); Error: PL/SQL: Statement ignored Line: 797 Text: Utl_File.FClose(out_file); 

So this is my code and it gives me this error, what is wrong?

+7
oracle plsql utl-file
source share
1 answer

First you need to create a directory object to access the C: \ test directory:

 CREATE OR REPLACE DIRECTORY CTEST AS 'C:\test'; GRANT READ ON DIRECTORY CTEST TO PUBLIC; 

Then you need to use this directory object when opening the file:

 DECLARE out_File UTL_FILE.FILE_TYPE; BEGIN out_File := UTL_FILE.FOPEN('CTEST', 'batotest.txt' , 'W'); UTL_FILE.PUT_LINE(out_file , 'Hi this is text file!'); UTL_FILE.FCLOSE(out_file); END; 

Share and enjoy.

+18
source share

All Articles