|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Export table data into text file through procedure/package [message #568048 is a reply to message #568043] |
Tue, 09 October 2012 04:54   |
 |
ashly
Messages: 23 Registered: October 2012
|
Junior Member |
|
|
Hi Michel,
But the result in retrieving 3,000,000 records is slow if compared with the code below:
SET SERVEROUTPUT ON
DECLARE
v_file UTL_FILE.FILE_TYPE;
v_buffer VARCHAR2(32767);
v_name VARCHAR2(128) := 'utl_file_buffered.txt';
v_lines PLS_INTEGER := 0;
c_eol CONSTANT VARCHAR2(1) := CHR(10);
c_eollen CONSTANT PLS_INTEGER := LENGTH(c_eol);
c_maxline CONSTANT PLS_INTEGER := 32767;
BEGIN
v_file := UTL_FILE.FOPEN('DUMP_DIR',v_name,'W',32767);
FOR r IN (SELECT u || ',' || v || ',' || w || ',' || x || ',' || y || ',' || z as csv FROM tbl1)
LOOP
IF LENGTH(v_buffer) + c_eollen + LENGTH(r.csv) <= c_maxline THEN
v_buffer := v_buffer || c_eol || r.csv;
ELSE
IF v_buffer IS NOT NULL THEN
UTL_FILE.PUT_LINE(v_file, v_buffer);
END IF;
v_buffer := r.csv;
END IF;
v_lines := v_lines + 1;
END LOOP;
UTL_FILE.PUT_LINE(v_file, v_buffer);
UTL_FILE.FCLOSE(v_file);
DBMS_OUTPUT.PUT_LINE('File='||v_name||'; Lines='||v_lines);
END;
/
Any advice?
[Updated on: Wed, 10 October 2012 04:28] by Moderator Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Export table data into text file through procedure/package [message #568200 is a reply to message #568193] |
Wed, 10 October 2012 04:17   |
 |
ashly
Messages: 23 Registered: October 2012
|
Junior Member |
|
|
Hi Michel, is this what you expecting?
[xyz@xyz-training ~]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Wed Oct 10 10:13:54 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn username@xe
Enter password:
Connected.
SQL> @unload.sql
SQL> set autotrace traceonly statistics
SQL>
SQL> set colsep ','
SQL> spool unload.csv
SQL> select * from tbl_1;
3000000 rows selected.
Statistics
----------------------------------------------------------
534 recursive calls
0 db block gets
237766 consistent gets
40261 physical reads
0 redo size
217141868 bytes sent via SQL*Net to client
2200374 bytes received via SQL*Net from client
200001 SQL*Net roundtrips to/from client
6 sorts (memory)
0 sorts (disk)
3000000 rows processed
SQL> spool off
SQL> exit
Disconnected from Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
[xyz@xyz-training ~]$
[Updated on: Wed, 10 October 2012 04:30] by Moderator Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|