-
Notifications
You must be signed in to change notification settings - Fork 1
/
table_info.sql
51 lines (48 loc) · 1.44 KB
/
table_info.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
set sqlformat json
set feedback off
set serveroutput on
set verify off
exec dbms_output.put_line('%%%START%%%');
select
ut.table_name,
cursor(
select
utc.column_name,
utc.data_type,
utc.nullable,
uc.constraint_type,
case when utc.data_type = 'VARCHAR2' then to_char(utc.char_length )
when utc.data_type = 'NUMBER' and (utc.data_precision is not null or utc.data_scale is not null)
then to_char(case when utc.data_precision is null then 0 else utc.data_precision end) || ',' || to_char(case when utc.data_scale is null then 0 else utc.data_scale end)
when utc.data_type like 'TIMESTAMP%' then null
else '0' end as data_length
-- TODO mdsouza: utc.hidden_column and utc.virtual_column
-- ,utc.*
from
user_tab_cols utc,
(
select
uc.table_name,
ucc.column_name,
ucc.position,
uc.constraint_type
from
user_constraints uc,
user_cons_columns ucc
where 1=1
and uc.constraint_type = 'P'
and uc.constraint_name = ucc.constraint_name
) uc
where 1=1
and utc.table_name = ut.table_name
--
and utc.table_name = uc.table_name(+)
and utc.column_name = uc.column_name(+)
order by uc.position nulls last, utc.column_id
) columns
from
user_tables ut
where 1=1
and ut.table_name in (&1)
;
exec dbms_output.put_line('%%%END%%%');