简体   繁体   中英

How to export/spool large table to file in Oracle

What are the convenient way to export/spool large table (43 million records) to single file in Oracle?

(Once we get the exported file, the purpose is to handle it in a Shell Script running in Solaris with kshell, but it is another history).

Our first try generated an empty file:

SET   NEWPAGE       0;
SET   LINESIZE    169;
SET   PAGESIZE      0;
SET   VERIFY      OFF;
SET   TERMOUT     OFF;
SET   COLSEP       '';
SET   FEEDBACK    OFF;
SET   HEADING     OFF;

SPOOL THE_MONSTER_FILE.txt;

SELECT
    a.field1, a.field2, b.field1, b.field2
FROM
    tableA a, tableB b,
WHERE
    a.id = b.id(+);

SPOOL OFF;
COMMIT;
EXIT;

You can easily do with help of SSIS packages.

Check link Here .

You can export the result set into a CSV file. Create a shell script and let it running on background, like this:

#!/bin/bash
cat <<EOF > THE_MONSTER_SCRIPT.sql
SET COLSEP ;
SET HEADSEP OFF
SET VERIFY OFF
SET HEADING OFF
SET ECHO OFF
SET FEEDBACK OFF
SET LONG 2000000000
SET LINESIZE 1000
SET PAGESIZE 0
SET TRIMSPOOL ON

SPOOL THE_MONSTER_FILE.csv;

SELECT
    a.field1, a.field2, b.field1, b.field2
FROM
    tableA a, tableB b,
WHERE
    a.id = b.id(+);

SPOOL OFF

EXIT
EOF

nohup sqlplus system/password@INSTNAME @THE_MONSTER_SCRIPT.sql &

If any of the columns on the result set have the column separator in its value, you have to enclose the columns with double quotes, replacing double quotes in the column value with two double quotes. Example:

/*
 * ----------------
 * | col1  | col2 |
 * ----------------
 * | a"a;a | aaa  |
 * | bbb;b | b"b  |
 * ----------------
 */

will turn into:

/*
 * "a""a;a";"aaa"
 * "bbb;b";"b""b"
 */

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM