from user_tab_columns where table_name=upper(p_tname); --获取表字段
type type_cursor is ref cursor ;
mycursor type_cursor;
outf utl_file.file_type; --导出文件类型
begin
v_fname:=p_tname||'.csv'; --导出的文件名和类型
for col in cursor_column loop
--判断字段类型,生成对应的数据格式
if col.data_type='DATE' then
v_sql:=v_sql||'to_char('||col.column_name||',''yyyy-mm-dd-hh24:mi:ss'')'||''',''';
else
v_sql:=v_sql||col.column_name||'||'',''||';
end if;
end loop;
v_sql:=rtrim(v_sql,'||'',''||'); --把拼接字段最后的拼接字符去除
v_sql:='select '||v_sql||' from '||p_tname;
dbms_output.put_line(v_sql);
outf:=utl_file.fopen('DIR_EXPORT',v_fname,'w'); --打开文件夹,创建文件
open mycursor for v_sql;
loop
fetch mycursor into v_line;
exit when mycursor%notfound;
--dbms_output.put_line(v_line); --控制台打印每条记录
utl_file.put_line(outf,v_line); --将每条记录写入文件
end loop;
utl_file.fclose(outf); --关闭文件读写流
dbms_output.put_line('导出成功');
end;
第三布:执行该存储过程得到 EMP.TXT里的如下数据
7369,SMITH,CLERK,7902,1980-12-17-00:00:00,800,200,20
7499,ALLEN,SALESMAN,7698,1981-02-20-00:00:00,1600,300,30
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/tongxinshuyu/article-51831-3.html
买国产手机
都有机场