ORA-29280 Oracle SQL 开发人员在尝试将表内容导出为 csv 时出错
Posted
技术标签:
【中文标题】ORA-29280 Oracle SQL 开发人员在尝试将表内容导出为 csv 时出错【英文标题】:ORA-29280 Oracle SQL developer error while trying to export table content as a csv 【发布时间】:2020-10-06 16:45:18 【问题描述】:create or replace procedure EXPORTTABLECONTENT is
file_handle UTL_FILE.file_type;
begin
file_handle := utl_file.fopen('CSV_DIR', 'csv.csv', 'w');
for i in (
select * from kwapp.minirules@ESDEV -- your query here
) loop
utl_file.put_line(file_handle,
i.RULEINDEX || ',' || i.RULENAME
);
end loop;
utl_file.fclose(file_handle);
end EXPORTTABLECONTENT;
我正在尝试从 minirules@ESDEV 导出表格内容,但由于某种原因我收到以下错误:
Connecting to the database EPS_ESDEV.
ORA-29280: invalid directory object
ORA-06512: at "SYS.UTL_FILE", line 41
ORA-06512: at "SYS.UTL_FILE", line 478
ORA-06512: at "AJ185194.EXPORTTABLECONTENT", line 4
ORA-06512: at line 2
【问题讨论】:
您真的可以访问名为“CSV_DIR”的目录吗? 【参考方案1】:您不能使用任何目录名称,只能使用您可以使用的目录名称之一。见
SQL> select * from all_directories;
OWNER DIRECTORY_NAME DIRECTORY_PATH
----- --------------- ---------------
SYS EXT_DIR c:\temp
使用您的代码(稍作修改以便在我的数据库中编译):
SQL> create or replace procedure exporttablecontent is
2 file_handle utl_file.file_type;
3 begin
4 file_handle := utl_file.fopen('CSV_DIR', 'csv.csv', 'w');
5
6 for i in (select * from dept) loop
7 utl_file.put_line(file_handle, i.deptno || ',' || i.dname);
8 end loop;
9 utl_file.fclose(file_handle);
10 end exporttablecontent;
11 /
Procedure created.
SQL> exec exporttablecontent;
BEGIN exporttablecontent; END;
*
ERROR at line 1:
ORA-29280: invalid directory path
ORA-06512: at "SYS.UTL_FILE", line 41
ORA-06512: at "SYS.UTL_FILE", line 478
ORA-06512: at "SCOTT.EXPORTTABLECONTENT", line 4
ORA-06512: at line 1
SQL>
但是,如果我使用我可用的目录(即SYS
授予我read
/write
权限):
SQL> create or replace procedure exporttablecontent is
2 file_handle utl_file.file_type;
3 begin
4 file_handle := utl_file.fopen('EXT_DIR', 'csv.csv', 'w'); --> here
5
6 for i in (select * from dept) loop
7 utl_file.put_line(file_handle, i.deptno || ',' || i.dname);
8 end loop;
9 utl_file.fclose(file_handle);
10 end exporttablecontent;
11 /
Procedure created.
SQL> exec exporttablecontent;
PL/SQL procedure successfully completed.
SQL>
它工作(如预期)。
SYS
如何授予目录权限?像这样:
SQL> connect sys as sysdba
Enter password:
Connected.
SQL> grant read, write on directory ext_dir to scott;
Grant succeeded.
SQL>
【讨论】:
以上是关于ORA-29280 Oracle SQL 开发人员在尝试将表内容导出为 csv 时出错的主要内容,如果未能解决你的问题,请参考以下文章
如何将 SQL 开发人员/Toad 连接到 Oracle 8i