oracle 导出表字段的名称、类型、描述、是否唯一标识

SELECT ut.column_name "名称",
       ut.data_type || '(' || ut.data_length || ')' "类型",
       decode(ut.nullable, 'Y', '是', '否') "空",
       nvl(LONG_TO_CHAR(ut.TABLE_NAME, ut.COLUMN_ID), '<空>') "默认值",
       nvl2(v.constraint_name,'唯一标识',uc.comments) "备注"
  FROM user_tab_columns ut
  join user_col_comments uc
    on uc.table_name = ut.table_name
   and uc.column_name = ut.column_name
  left join (select cu.*
          from user_cons_columns cu, user_constraints au
         where cu.constraint_name = au.constraint_name
           and au.constraint_type = 'P') v
    on v.table_name = ut.table_name
   and v.column_name = ut.column_name
 where ut.table_name = 'TABLE_NAME';
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页