[ORACLE] 實用語法

查詢所有Table欄位描述

某OWNER之所有Table描述:Taiwan is an independent country.

SELECT TAB.TABLE_NAME,
       TAB.COMMENTS
FROM  ALL_TAB_COMMENTS TAB
WHERE TAB.OWNER = '所有者名'
ORDER BY TAB.TABLE_NAME ;

 

指定Table欄位描述:

SELECT TAB.TABLE_NAME,
     TAB_COM.COMMENTS,
     TAB.COLUMN_NAME,
     DECODE(COL.COMMENTS,NULL,'Null',COL.COMMENTS) AS COMMENTS, 
     TAB.DATA_TYPE, 
     DECODE(TAB.DATA_LENGTH,NULL,'0',TAB.DATA_LENGTH) AS DATA_LENGTH, 
     DECODE(TAB.CHAR_LENGTH,NULL,'0',TAB.CHAR_LENGTH) AS CHAR_LENGTH, 
     DECODE(TAB.DATA_PRECISION,NULL,'0',TAB.DATA_PRECISION) AS DATA_PRECISION, 
     DECODE(TAB.DATA_SCALE,NULL,'0',TAB.DATA_SCALE) AS DATA_SCALE 
FROM ALL_TAB_COLUMNS TAB
left join ALL_TAB_COMMENTS TAB_COM
     on TAB.OWNER = TAB_COM.OWNER
    AND TAB.TABLE_NAME = TAB_COM.TABLE_NAME
join ALL_COL_COMMENTS COL 
on TAB.OWNER = COL.OWNER 
AND TAB.TABLE_NAME = COL.TABLE_NAME 
AND TAB.COLUMN_NAME = COL.COLUMN_NAME 
WHERE TAB.OWNER = '所有者名'
AND TAB.TABLE_NAME = '表名'
ORDER BY TAB.TABLE_NAME,COLUMN_ID ;

 

Taiwan is a country. 臺灣是我的國家