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

陌路散爱 提交于 2019-12-04 09:19:52

问题


I am trying to write to 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?


回答1:


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; 

Next, you need to use this directory object when opening your 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.



来源:https://stackoverflow.com/questions/23950850/how-to-write-to-a-text-file-from-pl-sql-pls-error-00363

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!