Oracle获取表结构信息:表名、是否视图、字段名、类型、长度、非空、主键
select a.TABLE_NAME as "TableName", case when (select count(*) from user_views v where v.VIEW_NAME =a.TABLE_NAME )>0 then ‘V‘ else ‘U‘end as "TableType", a.COLUMN_NAME as "ColumnName", A.COLUMN_ID as "ColumnIndex", a.DATA_TYPE as "DataType", case when a.DATA_TYPE = ‘NUMBER‘ then case when a.Data_Precision is null then a.Data_Length else a.Data_Precision end else a.Data_Length end as "Length", case when a.nullable = ‘N‘ then ‘0‘ else ‘1‘ end as "IsNullable", b.comments as "Description", case when (select count(*) from user_cons_columns c where c.table_name=a.TABLE_NAME and c.column_name=a.COLUMN_NAME and c.constraint_name= (select d.constraint_name from user_constraints d where d.table_name=c.table_name and d.constraint_type =‘P‘) )>0 then ‘1‘ else ‘0‘end as "IsPK" from USER_TAB_COLS a, sys.user_col_comments b where a.table_name = b.table_name and b.COLUMN_NAME = a.COLUMN_NAME order by a.TABLE_NAME, a.COLUMN_ID
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。