标签:io os ar 使用 for sp 文件 数据 on
本篇列举了几种把oracle 表中的数据导出成txt文件的方法,目前只列举了三种方式,如果后续发现更好的方法会持续添加进来。
1.plsqldev 里面有一个选项可以把表以execl格式到时
2.使用spool
sqlplus / as sysdba set linesize 1000 set pagesize 0 set echo off set termout off set heading off set feedback off SET trims ON set term off SET trimspool ON SET trimout ON spool '/archlog/exp/test.txt'; select OWNER||' , '||SEGMENT_NAME||' , '||PARTITION_NAME||' , ' from dba_segments where rownum<100; spool off;
#输出的test.txt文件头尾要编辑下
#set term off 只有在使用.sql脚本文件时才起作用,如上虽然指定了 set term off但是还是会把结果输出,也就是说set term off设置只对sql脚本有用
3.使用UTL_FILE程序包
##UTL_FILE.FOPEN第一个参数为文件路径,不能直接指定绝对路径,需要建立directory,然后指定我们建立的directory
sqlplus / as sysdba
create directory MY_DIR as ‘/home/oracle/‘;
grant read,write on directory dir_dump to HR;##也可以直接建立一个public directory
CREATE OR REPLACE PROCEDURE test
IS
testjiao_handle UTL_FILE.file_type;
BEGIN
test_handle := UTL_FILE.FOPEN('MY_DIR','test.txt','w');
FOR x IN (SELECT * FROM TESTJIAO) LOOP
UTL_FILE.PUT_LINE(test_handle,x.ID || ',' || x.RQ ||',');
END LOOP;
UTL_FILE.FCLOSE(test_handle);
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SUBSTR(SQLERRM,1,2000));
END;
/
标签:io os ar 使用 for sp 文件 数据 on
原文地址:http://blog.csdn.net/shaochenshuo/article/details/40507539