ITPub博客

首页 > 数据库 > Oracle > oracle导出数据到txt文件

oracle导出数据到txt文件

原创 Oracle 作者:1984008004 时间:2015-05-28 15:53:41 0 删除 编辑
要从 Oracle导出部分数据到文本文件中(flatfile),由于数据表很大,使用toad时导出失败,居然说内存溢出。看来还是用Oracle自己的命令来完成吧。

首先需要准备导出的目录,假设为 /opt/tmp,该目录需要Oracle的帐户可以读写。
create or replace directory utlexportpath as '/opt/tmp';

然后在sqlplus中即可使用如下方式把文件导出:

declare
    outfile utl_file.file_type;
begin
    outfile := utl_file.fopen('UTLEXPORTPATH','exp.txt','W');
    for rec in (select col1,col2 from sometable where your conditions)
    loop
       utl_file.put_line(outfile, rec.col1||','||rec.col2);
    end loop;
    utl_file.fclose(f);
end;

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/25903968/viewspace-1675475/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2013-04-03

  • 博文量
    38
  • 访问量
    133607