OracleにSQL構文でdesc関数機能を実現するサンプルコード

SQLコード:
SELECT A.COLUMN_NAME カラム名,
DATA_TYPE ||DECODE(DATA_TYPE,’DATE’,”,’CLOB’,”,’BLOB’,”,’BFILE’,”,’FLOAT’,”,’LONG RAW’,”,’LONG’,”,’RAW’,'(‘ || TO_CHAR(DATA_LENGTH) || ‘)’,

(DECODE(SIGN(INSTR(DATA_TYPE, ‘CHAR’)),1,
‘(‘ || TO_CHAR(DATA_LENGTH) || ‘)’,(DECODE(SUBSTR(DATA_TYPE, 1, 9),
‘TIMESTAMP’, ”,
(DECODE(NVL(DATA_PRECISION, -1), -1,
”,(DECODE(NVL(DATA_SCALE, 0), 0,
‘(‘ || TO_CHAR(DATA_PRECISION) || ‘)’, ‘(‘ || TO_CHAR(DATA_PRECISION) || ‘,’ ||
TO_CHAR(DATA_SCALE) || ‘)’))))))))) カラムタイプ,
A.NULLABLE 空はOK,
A.DATA_DEFAULT ディフォルト値,
B.COMMENTS カラムコメント
FROM ALL_TAB_COLUMNS A,
ALL_COL_COMMENTS B
WHERE B.TABLE_NAME=A.TABLE_NAME
AND A.OWNER=B.OWNER
AND A.COLUMN_NAME=B.COLUMN_NAME
AND A.TABLE_NAME =UPPER( ‘TABLE_NAME’)
AND A.OWNER =UPPER( ‘USER’)
ORDER BY COLUMN_ID;