oracle中把表匯出為txt檔案方法

來源:互聯網
上載者:User

標籤:io   os   ar   使用   for   sp   檔案   資料   on   

      本篇列舉了幾種把oracle 表中的資料匯出成txt檔案的方法,目前只列舉了三種方式,如果後續發現更好的方法會持續添加進來。

 

1.plsqldev 裡面有一個選項可以把表以execl格式到時

 

 

2.使用spool

sqlplus / as sysdbaset linesize 1000set pagesize 0set echo offset termout offset heading offset feedback offSET trims ONset term offSET trimspool ONSET trimout ONspool '/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 IStestjiao_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;/

 

 

 

oracle中把表匯出為txt檔案方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.