Re: S: unloader for Oracle

From: Parris Geiser <parris_at_walleye.esp.bellcore.com>
Date: 16 Mar 1995 21:50:05 GMT
Message-ID: <3kabqe$g8p_at_athos.cc.bellcore.com>


Hr.Kuhn (helmut_at_d255s271.mch.sni.de) wrote:
> Hi,
 

> I'm looking for an unloader-utility (SQL*Plus or Pro*C) which is
> able to unload tables from Oracle. I know that there were some
> postings concerning 'unload of a table' in former times, but at
> that time it was not interesting for me. Perhaps somebody outside
> has one or more of these tools that were published some months ago.
 

> Thanks in advance
> Helmut
> --
> Helmut Kuhn Tel: +49 89 636-2887
> Siemens-Nixdorf Informationssysteme AG Fax: +49 89 636-48332
> SNI MR PD 432 email: helmut.kuhn_at_mch.sni.de
> Otto-Hahn-Ring 6
> 81739 Muenchen



Try this:

rem Utility Unload.sql modified from public domain utility rem cpydlmtd.sql contained in IOUG 1992 utilities diskette. rem
rem Modifications 1993 Solution Engineering Inc.

rem                      sei_at_elmwood.com
rem !# Creates a SQL*Loader data file containing data description and
rem !# data.
rem !# This version tailored for ORACLE7.

SET ECHO OFF
SET FEED OFF
SET HEA OFF
SET VER OFF
SET PAGES 0
SET SPACE 0
SET RECSEP OFF
SET LINESIZE 80
prompt parameters are

prompt ..               1: user name,
prompt ..               2: table name,
prompt ..               3: output file name (Without extension .ctl)

undefine owner
undefine table
undefine outfile
define owner = &1
define table = &2
define outfile = &3

Prompt 'Copying data into &outfile..ctl where the original owner ', Prompt 'is &owner and the table name is &table.' prompt
PROMPT Loading command: SQLLOAD un/pw &outfile..ctl

SET TERM OFF
spool unload.tmp

COLUMN CR PRINT FOLD_AFTER 1
COLUMN LINELTH FORMAT 9999
COLUMN LRECL FORMAT 0999
SELECT 'SET LINESIZE ',

        sum(decode(data_type,'NUMBER',
                             decode(nvl(data_scale,0),0,
                                    nvl(data_precision,20)+2,
                                        data_precision+3),
                             'DATE',10,data_length+3)) linelth, ' ' CR
  FROM ALL_TAB_COLUMNS
 WHERE OWNER      = UPPER('&owner')

   AND TABLE_NAME = UPPER('&table')
/
SELECT 'SPOOL &outfile..ctl' FROM DUAL
/
SELECT 'prompt LOAD DATA' CR, 
       'prompt INFILE *' CR, 
       'prompt INTO TABLE &table' CR,
       'prompt FIELDS TERMINATED BY '','' OPTIONALLY ENCLOSED BY ''"'' ' 
CR,
       'prompt ( ' cr 

from dual;

REM Get first without comma:
select 'prompt ', column_name
 FROM ALL_TAB_COLUMNS
 WHERE OWNER = UPPER('&owner')
   AND TABLE_NAME = UPPER('&table')
 AND COLUMN_ID = 1
 ;

REM Get rest with leading comma:
select 'prompt ', ' ,'||column_name
 FROM ALL_TAB_COLUMNS
 WHERE OWNER = UPPER('&owner')
   AND TABLE_NAME = UPPER('&table')
 AND COLUMN_ID > 1
 order by column_id;

SELECT 'prompt ) ' cr ,

       'prompt BeginData ' cr 
       from dual;


SELECT 'SELECT '||decode(
                                  data_type,'CHAR',
                  '''"''||'||column_name||'||''"''',
                                  'VARCHAR2',
                                  '''"''||'||column_name||'||''"''',
                  column_name)
  FROM ALL_TAB_COLUMNS
 WHERE OWNER      = UPPER('&owner')

   AND TABLE_NAME = UPPER('&table')
   AND COLUMN_ID = 1
/
SELECT '||'',''||'||decode(data_type,'CHAR',
                  '''"''||'||column_name||'||''"''',
                                  'VARCHAR2',
                                  '''"''||'||column_name||'||''"''',
                  column_name)
  FROM ALL_TAB_COLUMNS
 WHERE OWNER      = UPPER('&owner')

   AND TABLE_NAME = UPPER('&table')
   AND COLUMN_ID > 1
ORDER BY COLUMN_ID
/
SELECT 'FROM &owner..&table;' FROM DUAL
/
SELECT 'SPOOL OFF' FROM DUAL
/
/
SPOOL
SPOOL OFF
START unload.tmp
HOST rm unload.tmp
SET LINESIZE 80
SET FEED 6
SET HEA ON
SET VER ON
SET PAGES 14
SET ECHO ON
SET TERM ON exit Received on Thu Mar 16 1995 - 22:50:05 CET

Original text of this message