【Oracle】查询字段的长度、类型、精度、注释等信息

 

查询数据字典中字段的相关信息

SELECT
T .column_name AS column_name, --列名
T .column_type AS column_type, ---字段类型
T .data_length AS data_length, --字段长度
T .data_scale AS data_scale, --字段精度
T .column_comment AS column_comment, --字段注释
case when substr(b.constraint_type,1,1)='P' then 'N' else null end as Is_PrimaryKey, --是否主键
DECODE(T.nullable,'N',T.nullable,NULL) nullable –是否为空
FROM
(
SELECT
UB.tablespace_name AS database_name,
UTC.table_name AS table_name,
UTC.column_name AS column_name,
UTC.data_length AS data_length,
UTC.data_type AS column_type,
utc.data_scale AS data_scale,
ucc.comments AS column_comment,
utc.column_id,
utc.nullable
FROM
user_tables ub
LEFT JOIN user_tab_columns utc ON ub.table_name = UTC.table_name
LEFT JOIN user_col_comments ucc ON utc.column_name = ucc.column_name
AND utc.table_name = ucc.table_name
) T
LEFT JOIN (
SELECT
UCC.table_name AS table_name,
ucc.column_name AS column_name,
wm_concat (UC.constraint_type) AS constraint_type
FROM
user_cons_columns ucc
LEFT JOIN user_constraints uc ON UCC.constraint_name = UC.constraint_name
GROUP BY
UCC.table_name,
ucc.column_name
) b ON T .table_name = b.TABLE_NAME
AND T .column_name = b.column_name
where T.table_name='表名' 
order by T.column_id

你可能感兴趣的:(【Oracle】查询字段的长度、类型、精度、注释等信息)