查询 Oracle 表的基本结构(写文档)

SELECT mdata.table_name, mdata.column_name, 
 mdata.data_type,mdata.data_length,mdata.data_precision,mdata.data_scale,
mdata.comments,
CASE mdata.nullable WHEN NULL THEN '非空' ELSE '' END AS nullable,edata.keytype FROM(
SELECT utc.table_name, utc.column_name, utc.data_length,utc.data_precision,utc.data_scale, 
utc.data_type,ucc.comments,utc.nullable FROM user_tab_columns utc,user_col_comments ucc 
WHERE utc.table_name = ucc.table_name AND utc.column_name = ucc.column_name
) mdata,(
  SELECT ucc.table_name,ucc.constraint_name,ucc.column_name, case uc.constraint_type WHEN 'P' THEN '主键' ELSE '' END AS keytype FROM user_cons_columns ucc,user_constraints uc 
  WHERE ucc.constraint_name = uc.constraint_name
) edata WHERE mdata.table_name = edata.table_name(+) AND mdata.column_name = edata.column_name(+)
posted @ 2013-03-27 14:21  中小刀  阅读(198)  评论(0编辑  收藏  举报