一个从数据库中把数据导成txt的笨办法
create directory DIR_DUMP as '/oradata/data_dump';
CREATE OR REPLACE PROCEDURE anlp_to_txt
IS
testjiao_handle UTL_FILE.file_type;
BEGIN
testjiao_handle := UTL_FILE.FOPEN('DIR_DUMP','anlp.txt','w');
FOR x IN (SELECT * FROM sapsr3.ANLP) LOOP
UTL_FILE.PUT_LINE(testjiao_handle,x.MANDT ||' '||x.BUKRS ||' '||x.GJAHR ||' '||x.PERAF ||' '||x.AFBNR ||' '||x.ANLN1 ||' '||x.ANLN2 ||' '||x.AFABER||' '||x.ZUJHR ||' '||x.ZUCOD ||' '||x.AUFWP ||' '||x.AUFWB ||' '||x.AUFWZ ||' '||x.NAFAP ||' '||x.NAFAG ||' '||x.NAFAZ ||' '||x.SAFAP ||' '||x.SAFAG ||' '||x.SAFAZ ||' '||x.AAFAP ||' '||x.AAFAG ||' '||x.AAFAZ ||' '||x.MAFAP ||' '||x.MAFAG ||' '||x.MAFAZ ||' '||x.ZINSP ||' '||x.ZINSG ||' '||x.ZINSZ ||' '||x. AUFNP||' '||x.AUFNG ||' '||x.AUFNZ ||' '||x.ANSWL||' '||x.INVZM ||' '||x.KTOGR ||' '||x.AFASL ||' '||x.KOSTL ||' '||x.GSBER ||' '||x.CAUFN ||' '||x.XUNUL ||' '||x.ANUPD ||' '||x.FKBER ||' '||x.BELNR||' '||x.LSTAR||' '||x.GEBER||' '||x.GRANT_NBR||' '||x.GEBER2||' '||x.FKBER2||' '||x.GRANT_NBR2||' '||x.FISTL2||' '||x.IMKEY||' '||x.PS_PSP_PNR2||' '||x.BUDGET_PD||' '||x.BUDGET_PD2||' '||x.SEGMENT||' '||x.PRCTR||' '||x.FISTL);
END LOOP;
UTL_FILE.FCLOSE(testjiao_handle);
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SUBSTR(SQLERRM,1,2000));
END;
/
学习:http://blog.sina.com.cn/s/blog_61c006ea0100l6vx.html
笔记