REM **************************************************************
REM David L. Hunt (file author) distributes this and other
REM files/scripts for educational purposes only, to illustrate the
REM use or application of various computing techniques. The author
REM makes no warranty regarding this script's fitness for any
REM industrial application or purpose nor is there any claim that
REM this or any similarly-distributed scripts are error free or
REM should be used for any purpose other than illustration.
REM **************************************************************
set echo off
set verify off
set feedback off
set linesize 100
set pagesize 500
break on "#" on a on b
accept x prompt "Enter table name: "
col a format a18 heading "Column|Name" word_wrapped
col b format a13 heading "Data Type|and Length"
col c format a43 heading "[Constraint Type: Name: En-/Dis-abled]|and Enforcement" word_wrapped
col "#" format 99 heading "Col| # "
exec prep_user_constraints('&x')
(select column_id "#",
col.column_name a,
col.data_type ||
decode(substr(data_type,1,4),
'DATE',null,
'LONG',null,
'VARC','('||ltrim(to_char(data_length,'9999'))||')',
'CHAR','('||ltrim(to_char(data_length,'999'))||')',
'FLOA','('||ltrim(to_char(data_precision,'99'))||
decode(data_scale,
0,null,
','||ltrim(to_char(data_scale,'9999')))||')'
,null,
'NUMB','('||ltrim(to_char(data_precision,'99'))||
decode(data_scale,
0,null,
','||ltrim(to_char(data_scale,'999')))||')'
,null)
b,
'[' ||
decode(con.constraint_type,'P','PK','R','FK','C','CK','U','UK')
|| ':' ||con.constraint_name
|| ':' ||con.status
|| '] ' ||
decode(con.constraint_type,
'P','NOT NULL/UNIQUE',
'U','UNIQUE',
'C',con.search_condition,
'R','Match : '||r_constraint_name) c
from temp_cons con,
user_cons_columns con_col,
user_tab_columns col
where col.table_name = upper('&x')
and con.constraint_name = con_col.constraint_name
and col.table_name = con_col.table_name
and col.column_name = con_col.column_name
)
union
((select column_id "#",
col.column_name a,
col.data_type ||
decode(substr(data_type,1,4),
'DATE',null,
'LONG',null,
'VARC','('||ltrim(to_char(data_length,'9999'))||')',
'CHAR','('||ltrim(to_char(data_length,'999'))||')',
'FLOA','('||ltrim(to_char(data_precision,'99'))||
decode(data_scale,
0,null,
','||ltrim(to_char(data_scale,'9999')))||')'
,null,
'NUMB','('||ltrim(to_char(data_precision,'99'))||
decode(data_scale,
0,null,
','||ltrim(to_char(data_scale,'999')))||')'
,null)
b,
' ' c
from user_tab_columns col
where col.table_name = upper('&x'))
minus
(select column_id "#",
col.column_name a,
col.data_type ||
decode(substr(data_type,1,4),
'DATE',null,
'LONG',null,
'VARC','('||ltrim(to_char(data_length,'9999'))||')',
'CHAR','('||ltrim(to_char(data_length,'999'))||')',
'FLOA','('||ltrim(to_char(data_precision,'99'))||
decode(data_scale,
0,null,
','||ltrim(to_char(data_scale,'9999')))||')'
,null,
'NUMB','('||ltrim(to_char(data_precision,'99'))||
decode(data_scale,
0,null,
','||ltrim(to_char(data_scale,'999')))||')'
,null)
b,
' ' c
from user_tab_columns col, user_cons_columns con_col
where col.table_name = upper('&x')
and col.table_name = con_col.table_name
and col.column_name = con_col.column_name)
)
order by 1
/
accept again prompt "Another table (Y/N) ? "
set heading off
set pagesize 0
spool temp.sql
set termout off
select decode(upper('&again'),'Y','@stru') from dual;
set termout on
spool off
set heading on
set pagesize 23
set feedback on
@temp