DECLARE
row_result varchar2(4000);
selectsql varchar2(4000);
qrycursor SYS_REFCURSOR;
txt_handle UTL_FILE.file_type;
BEGIN
selectsql := 'select USER_ID||chr(9)||EXTERNAL_ID||chr(9)||ACCOUNT_ID||chr(9)||CERTIFY_STATUS||chr(9)||USER_STATUS||chr(9)||RUNTIME_STATUS||chr(9)||USER_NAME||chr(9)||REAL_NAME||chr(9)||COUNTRY||chr(9)||GENDER||chr(9)||PROFESSION||chr(9)||ADDRESS||chr(9)||PHONE||chr(9)||MOBILE||chr(9)||EMAIL||chr(9)||CERT_TYPE||chr(9)||CERT_NO||chr(9)||LICENSE_VALID_TIME||chr(9)||REGISTER_FROM||chr(9)||ORIGIN_REGISTER_FROM||chr(9)||RAW_ADD_TIME||chr(9)||RAW_UPDATE_TIME||chr(9)||BANK_CARD_NO||chr(9)||BANK_CARD_TYPE||chr(9)||NAME||chr(9)||BANK_CERT_NO from yhcheck.til_per';
txt_handle := UTL_FILE.FOPEN('TESTDIR', 'b.txt', 'w',32767);
open qrycursor for selectsql;
loop
fetch qrycursor
into row_result;
exit when qrycursor%notfound;
UTL_FILE.PUT_LINE(txt_handle, row_result);
end loop;
--关闭游标
close qrycursor;
UTL_FILE.FCLOSE(txt_handle);
end;
逗号分隔
DECLARE
row_result varchar2(4000);
selectsql varchar2(4000);
qrycursor SYS_REFCURSOR;
txt_handle UTL_FILE.file_type;
BEGIN
selectsql := 'select id || '','' || name || '','' || dti
from testdump
where name = ''gaopeng''
and dti > to_date(''2015-03-17 00:00:00'', ''yyyy-mm-dd hh24:mi:ss'')';
txt_handle := UTL_FILE.FOPEN('DATA_PUMP_DIR', 'b.txt', 'w', 32767);
open qrycursor for selectsql;
loop
fetch qrycursor
into row_result;
exit when qrycursor%notfound;
UTL_FILE.PUT_LINE(txt_handle, row_result);
end loop;
--关闭游标
close qrycursor;
UTL_FILE.FCLOSE(txt_handle);
end;
注意点 1: 'w'可以更改为'a'为追加
2: 32767为每行的宽度,默认为1024
3: TESTDIR为大写是 CREATE DIRECTORY建立的目录
4: chr(9) 为TAB分割
row_result varchar2(4000);
selectsql varchar2(4000);
qrycursor SYS_REFCURSOR;
txt_handle UTL_FILE.file_type;
BEGIN
selectsql := 'select USER_ID||chr(9)||EXTERNAL_ID||chr(9)||ACCOUNT_ID||chr(9)||CERTIFY_STATUS||chr(9)||USER_STATUS||chr(9)||RUNTIME_STATUS||chr(9)||USER_NAME||chr(9)||REAL_NAME||chr(9)||COUNTRY||chr(9)||GENDER||chr(9)||PROFESSION||chr(9)||ADDRESS||chr(9)||PHONE||chr(9)||MOBILE||chr(9)||EMAIL||chr(9)||CERT_TYPE||chr(9)||CERT_NO||chr(9)||LICENSE_VALID_TIME||chr(9)||REGISTER_FROM||chr(9)||ORIGIN_REGISTER_FROM||chr(9)||RAW_ADD_TIME||chr(9)||RAW_UPDATE_TIME||chr(9)||BANK_CARD_NO||chr(9)||BANK_CARD_TYPE||chr(9)||NAME||chr(9)||BANK_CERT_NO from yhcheck.til_per';
txt_handle := UTL_FILE.FOPEN('TESTDIR', 'b.txt', 'w',32767);
open qrycursor for selectsql;
loop
fetch qrycursor
into row_result;
exit when qrycursor%notfound;
UTL_FILE.PUT_LINE(txt_handle, row_result);
end loop;
--关闭游标
close qrycursor;
UTL_FILE.FCLOSE(txt_handle);
end;
逗号分隔
DECLARE
row_result varchar2(4000);
selectsql varchar2(4000);
qrycursor SYS_REFCURSOR;
txt_handle UTL_FILE.file_type;
BEGIN
selectsql := 'select id || '','' || name || '','' || dti
from testdump
where name = ''gaopeng''
and dti > to_date(''2015-03-17 00:00:00'', ''yyyy-mm-dd hh24:mi:ss'')';
txt_handle := UTL_FILE.FOPEN('DATA_PUMP_DIR', 'b.txt', 'w', 32767);
open qrycursor for selectsql;
loop
fetch qrycursor
into row_result;
exit when qrycursor%notfound;
UTL_FILE.PUT_LINE(txt_handle, row_result);
end loop;
--关闭游标
close qrycursor;
UTL_FILE.FCLOSE(txt_handle);
end;
注意点 1: 'w'可以更改为'a'为追加
2: 32767为每行的宽度,默认为1024
3: TESTDIR为大写是 CREATE DIRECTORY建立的目录
4: chr(9) 为TAB分割