Flat.cmd
@echo off
if "%1"=="" goto :usage
if "%2"=="" goto :usage
sqlplus -s %1 @flat.sql %2
goto :done
:Usage
echo "usage flat un/pw [tables|views]"
echo "example flat scott/tiger emp dept"
echo "description Select over standard out all rows of table or view with "
echo " columns delimited by tabs."
:done
Flat.sql
set wrap off
set linesize 100
set feedback off
set pagesize 0
set verify off
set termout off
spool ytmpy.sql
prompt select
select lower(column_name)||'||chr(9)||'
from user_tab_columns
where table_name = upper('&1') and
column_id != (select max(column_id) from user_tab_columns where
table_name = upper('&1'))
order by column_id
/
select lower(column_name)
from user_tab_columns
where table_name = upper('&1') and
column_id = (select max(column_id) from user_tab_columns where
table_name = upper('&1'))
order by column_id
/
prompt from &1
prompt /
spool off
set termout on
@ytmpy.sql
exit
