注:我在例子中用的是scott用户,oracle版本为 9.2.0.1
首先,先授予用户scott的相应directory权限
grant create any directory to scott;
grant drop any dirctory to scott;(删除权限)
其次,创建directory
create or replace directory report_dir as 'd:\temp';
然后,使用该directory
create or replace procedure bulk_rowtype is
f utl_file.file_type;
begin
f := utl_file.fopen('REPORT_DIR','report.dat','W');
for i in (select * from t) loop
utl_file.put_line(f,'a='||i.a||',b='||i.b||',c='||i.c||',d='||i.d);
end loop;
utl_file.fclose(f);
end;
/
特别强调: f := utl_file.fopen('REPORT_DIR','report.dat','W');
该句中,report_dir 应写成大写 REPORT_DIR,否则会提示
ORA-29280: 目录路径无效
最后提示:在oracle9.2版本中utl_file不再使用utl_file_dir参数。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10037372/viewspace-663253/ ,如需转载,请注明出处,否则将追究法律责任。