Oracle 使用SQL查询表结构:字段名称、类型、长度、备注、必填、是否主外键


select a.COLUMN_NAME 字段,
       (select b.comments from user_col_comments b where b.table_name = a.table_name and b.column_name = a.column_name) 字段名称,
       decode(a.data_type, 'VARCHAR2', 'VARCHAR', a.data_type)||'('||a.data_length||')'   字段类型,
       decode(a.nullable, 'N', 'Y', 'N')   是否必填,
       decode(a.COLUMN_NAME, 'ID', 'Y', 'N') 是否主键,
       decode(a.COLUMN_NAME, 'ROOMID', 'Y', 'N') 是否外键,
       (select b.comments from user_col_comments b where b.table_name = a.table_name and b.column_name = a.column_name) x
  from user_tab_columns a
 where table_name = 'XXXXXX';

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