ORACLE 查询表字段信息(是否主键)

select
    utc.column_name as 字段名,utc.data_type 数据类型,utc.data_length 最大长度,
CASE utc.nullable WHEN 'N' THEN '否' ELSE '是' END 可空,
utc.data_default 默认值,ucc.comments 注释,UTC.table_name 表名,
   CASE UTC.COLUMN_NAME 
  WHEN (select
 col.column_name 
from
 user_constraints con,user_cons_columns col
where
 con.constraint_name=col.constraint_name and con.constraint_type='P'
 and col.table_name='tableName')   THEN '是' ELSE '否' END AS 主键
from
    user_tab_columns utc,user_col_comments ucc
where
    utc.table_name = ucc.table_name
    and utc.column_name = ucc.column_name
    and utc.table_name = 'tableName
order by
    column_id;

你可能感兴趣的:(oracle,oracle,数据库,sql)