Tuesday, April 22, 2008

Script to convert table data into comma delimited format

set pagesize 0
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 pages 0 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

No comments: