col 列名 format a26
col null format a4
col データ型 format a13
col "index(PK)" format a9
col "index(Not PK)" format a13
select
tc.column_name "列名",
decode(nvl(tc.data_scale,0),0,
decode(tc.data_type,'NUMBER',
tc.data_type || '(' || ltrim(to_char(tc.data_precision)) || ')',
decode(tc.data_type,'VARCHAR2',
tc.data_type || '(' || ltrim(to_char(tc.data_length)) || ')',
decode(tc.data_type,'CHAR',
tc.data_type || '(' || ltrim(to_char(tc.data_length)) || ')',
tc.data_type
)
)
),
tc.data_type || '(' || ltrim(to_char(tc.data_precision)) || ',' || ltrim(to_char(tc.data_scale)) || ')'
) "データ型",
decode(tc.nullable,'Y',' ','No') "Null",
decode(mod(v.v_isPrim,2),1,'○',null) "index(PK)",
decode(greatest(nvl(v.v_isPrim,0),1),1,null,'○') "index(Not PK)"
from user_tab_columns tc,
(
select ic.column_name as v_column_name,
sum(decode (ic.index_name,c.constraint_name,1,2)) as v_isPrim
from user_ind_columns ic, user_constraints c, user_indexes i
where ic.table_name = c.table_name (+)
and ic.index_name = i.index_name (+)
and 'P' = c.constraint_type (+)
and c.status = 'ENABLED'
and ic.table_name = upper('&&1')
and c.table_name (+) = upper('&&1')
group by ic.column_name
) v
where tc.table_name = upper('&&1')
and tc.column_name = v.v_column_name (+)
order by tc.column_id
;