【发布时间】:2020-02-24 10:04:11
【问题描述】:
我正在尝试使用带有“utl_file”的“PL/SQL”创建一个 txt 文件,但我遇到了一些问题。这是我的代码
procedure testFile Is
out_File Utl_File.File_Type;
CREATE OR REPLACE DIRECTORY tmp AS 'C:\Users\jsnow\Documents';
GRANT read, write ON DIRECTORY tmp TO jack;
Begin
out_file:=utl_file.fopen(tmp,'test.txt','W');
utl_file.put_line(out_file,'Test!');
utl_file.fclose(out_file);
Exception when others then
Dbms_output.put_line(sqlerrm ||'-------'||Sqlcode);
end testfile;
当我尝试编译这个脚本时,我得到了这个错误:
PLS-00103: Encountered the symbol "CREATE" when expecting one of the following:
begin function pragma procedure subtype type <an identifier>
<a double-quoted delimited-identifier> current cursor delete
exists prior
您知道如何在存储过程中创建文本文件吗? 提前谢谢你。
【问题讨论】:
-
我只想重申 Littlefoot 的“不要那样做”的评论。试图在一个过程中创建对象并授予权限是非常非常糟糕的设计的证据。没有充分的理由在应用程序构建期间不能/不应该使用简单的 SQL 来完成这些操作。这适用于所有 DDL。