① 新建文件 test.sql 把下面代码copy 到test.sql 脚本中
spool j:\test.txt select sysdate from dual; spool off;
② 执行命令 @ j:\test.sql,输出结果就保存到了test.txt文件中了。
补充:sql查询结果写入txt
什么也不说,直接来个例子。
create or replace procedure proc_insertsqltxt as
v_file utl_file.file_type;
v_input clob;
begin
v_file := utl_file.fopen('data_pump_dir', 'empno.txt', 'w');
for i in (select empno||'|'||
ename||'|'||
job ||'|'||
mgr ||'|'||
to_char(hiredate,'yyyy-mm-dd') ||'|'||
sal ||'|'||
comm ||'|'||
deptno as stringname from scott.emp)
loop
utl_file.put_line(v_file,i.stringname);
end loop;
utl_file.fclose(v_file);
exception
when utl_file.access_denied then
dbms_output.put_line('拒绝访问!');
when others then
dbms_output.put_line('sqlerrm: ' || sqlerrm);
end;
以上为个人经验,希望能给大家一个参考,也希望大家多多支持www.887551.com。如有错误或未考虑完全的地方,望不吝赐教。