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: Data Dump

Re: Data Dump

From: Keith Boulton <boulke_at_globalnet.co.uk>
Date: 1997/11/19
Message-ID: <34721f39.13057235@read.news.global.net.uk>#1/1

On Mon, 17 Nov 1997 17:34:24 -0600, Ed Gillispie <eg76440_at_deere.com> wrote:

>Does any one have a script that will dump the data from a selected
>Oracle table (preferably in the order of the primary key) to an ASCII
>text file for loading to a mainframe?
>
>Your help is greatly appreciated!

The following sqlplus command file will do the sort of thing required assuming that you require a text format file. If you require binary representation of numbers etc then it would get more tricky.

spool off
exit success

This can be run with e.g.
sqlplus / @d:\fred.sq

Within a script, the return code should be checked for errors. The whenever ...error exit .. may need to be modified on systems (e.g. AIX) where the exit code is limited to the range 0 - 255.

Alternatively, you can use PL/SQL file io functions which are significantly faster e.g.

create or replace procedure dumpf as
  f utl_file.file_type;
  cursor c is
    select rpad(to_char(a),11) || b x
    from bill
    order by a;
begin
  f := utl_file.fopen('d:\temp','test1.txt', 'w' );   for r in c loop

     utl_file.put_line( f, r.x );
  end loop;
  utl_file.fflush(f);
  utl_file.fclose(f);
end;
/

I thought this could be speeded up by using put to avoid flushing the output buffer which I think is what put_line does e.g.

create or replace procedure dumpf as
  f utl_file.file_type;
  cursor c is
    select rpad(to_char(a),11) || b || chr(10) x     from bill
    order by a;
begin
  f := utl_file.fopen('d:\temp','test1.txt', 'w' );   for r in c loop

     utl_file.put( f, r.x );
  end loop;
  utl_file.fflush(f);
  utl_file.fclose(f);
end;
/

This works a lot faster. It also highlights a bug in the file i/o functions, only the first 2k or so of output is written to the file, despite the fact that no error is reported. Received on Wed Nov 19 1997 - 00:00:00 CST

Original text of this message

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