Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Opposite of SQL*Loader

Re: Opposite of SQL*Loader

From: Oracleguru <oracleguru_at_mailcity.com>
Date: Tue, 11 Aug 1998 14:55:59 GMT
Message-ID: <01bdc547$cedd4740$a504fa80@mndnet>


Here is a script that can give you the ASCII dump. As you can see, I did not write it. Jared Still wrote it. Its beautiful !!!

Oracleguru
www.oracleguru.net
oracleguru_at_mailcity.com

set trimspool on
set serverout on
clear buffer
undef dumpfile
undef dumptable
undef dumpowner
var maxcol number
var linelen number
var dumpfile char(40)
col column_id noprint
set pages0 feed off termout on echo off verify off accept dumpowner char prompt 'Owner of table to dump: ' accept dumptable char prompt 'Table to dump: ' begin

        select max(column_id) into :maxcol
        from all_tab_columns
        where table_name = rtrim(upper('&dumptable'))
        and owner = rtrim(upper('&dumpowner'));
        select sum(data_length) + ( :maxcol * 3 ) into :linelen
        from all_tab_columns
        where table_name = rtrim(upper('&dumptable'))
        and owner = rtrim(upper('&dumpowner'));
end;
/
print linelen
print maxcol
spool ./_dump.sql
select 'set trimspool on' from dual;
select 'set termout off pages 0 heading off echo off' from dual;
select 'set line ' || :linelen from dual;
select 'spool ' || lower('&dumptable') || '.txt' from dual;
select 'select' || chr(10) from dual;
select '   ' || '''' || '"'  || '''' || ' || ' ||
        'replace(' || column_name || ',' || '''' ||  '"' || '''' || ') '
        || ' ||' || '''' || '",' || '''' || ' || ',
        column_id

from all_tab_columns
where table_name = upper('&dumptable')
and owner = upper('&dumpowner')
and column_id < :maxcol
union
select ' ' || '''' || '"' || '''' || ' || ' ||
        'replace(' || column_name  || ',' || '''' ||  '"' || '''' || ') '
        || ' ||' || '''' || '"' || '''',
        column_id

from all_tab_columns
where table_name = upper('&dumptable')
and owner = upper('&dumpowner')
and column_id = :maxcol
order by 2
/
select 'from &dumpowner..&dumptable' from dual;
select '/' from dual;
select 'spool off' from dual;

spool off
@@_dump
set line 79
-- build a basic control file

spool _dtmp.sql
select 'spool ' || lower('&dumptable') || '.par' from dual; spool off
@@_dtmp  

select 'userid = /' || chr(10) ||

        'control = ' || lower('&dumptable') || '.ctl' || chr(10) ||
        'log = ' || lower('&dumptable') || '.log' || chr(10) ||
        'bad = ' || lower('&dumptable')|| '.bad' || chr(10)
from dual;
spool _dtmp.sql
select 'spool ' || lower('&dumptable') || '.ctl' from dual; spool off
@@_dtmp
select 'load data' || chr(10) ||

        'infile ' || ''''|| lower('&dumptable') || '.txt' || '''' || chr(10) ||

        'into table &dumptable' || chr(10) ||
        'fields terminated by ' || '''' || ',' || '''' ||
        'optionally enclosed by ' || '''' || '"' || '''' || chr(10)
from dual;
select '(' from dual;
select ' ' || column_name || ',' ,

        column_id
from all_tab_columns
where table_name = upper('&dumptable')
and owner = upper('&dumpowner')
and column_id < :maxcol
union
select ' ' || column_name, column_id
from all_tab_columns
where table_name = upper('&dumptable')
and owner = upper('&dumpowner')
and column_id = :maxcol
order by 2
/
select ')' from dual;
exit

Andrew D. Arenson <arenson_at_swan.imgen.bcm.tmc.edu> wrote in article <wqemuor4ot.fsf_at_swan.imgen.bcm.tmc.edu>...

> 
> I am familiar with the Sybase utility bcp (bulk copy) which can
> be used to copy tab-delimited files of data into or out of a Sybase
> table.
> 
> I would like to do the same thing in Oracle. From what I've read,
> SQL*Loader will achieve this handily and with _much_ more flexibility
> when I want to load data INTO an Oracle table.
> 
> What do I use to bulk copy data OUT OF an Oracle table?
> 
> I understand that I could write a fairly simple piece of code to do
> this, but I find it hard to believe that there isn't a utility like
> SQL*Loader for drawing data out of an Oracle table.
> 
> Andy
> 
> 
> 
> -- 
> Andrew D. Arenson            |
http://gc.bcm.tmc.edu:8088/cgi-bin/andy/andy

> Baylor College of Medicine   | arenson_at_bcm.tmc.edu        (713)  H
520-7392
> Genome Sequencing Center, Molecular & Human Genetics Dept.     | W
798-4689
> One Baylor Plaza, Room S903, Houston, TX 77030                 | F
798-5386
> Received on Tue Aug 11 1998 - 09:55:59 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US