Oracle get column/comment definitions for a table

select a.table_name,c.comments,a.column_name,b.comments,
       decode(a.data_type,'VARCHAR2',a.data_type||'('||a.data_length||')','CHAR',a.data_type||'('||a.data_length||')','NUMBER',decode(a.data_precision,'',a.data_type,a.data_type||'('||a.data_precision||','||a.data_scale||')'),a.data_type),
      'AS '||a.column_name||',',
      decode(b.comments,'','','--'||b.comments),
      decode(b.comments,'','',a.column_name||' AS '||B.COMMENTS||',')
from dba_tab_cols a,dba_col_comments b,dba_tab_comments c
where a.table_name='TEST1114'
and a.owner = 'DB2'
and a.owner = b.owner
and b.owner = c.owner
and a.table_name = b.table_name
and a.column_name = b.column_name
and a.table_name = c.table_name
order by a.column_id; 

  


select a.table_name,c.comments,a.column_name,b.comments,       decode(a.data_type,'VARCHAR2',a.data_type||'('||a.data_length||')','CHAR',a.data_type||'('||a.data_length||')','NUMBER',decode(a.data_precision,'',a.data_type,a.data_type||'('||a.data_precision||','||a.data_scale||')'),a.data_type),      'AS '||a.column_name||',',      decode(b.comments,'','','--'||b.comments),      decode(b.comments,'','',a.column_name||' AS '||B.COMMENTS||',')from dba_tab_cols a,dba_col_comments b,dba_tab_comments cwhere a.table_name='DML_SD_BANK_GL'and a.owner = 'UUPSDB2'and a.owner = b.ownerand b.owner = c.ownerand a.table_name = b.table_nameand a.column_name = b.column_nameand a.table_name = c.table_nameorder by a.column_id; 

posted @ 2018-11-14 14:56  Ayumie  阅读(258)  评论(0编辑  收藏  举报