세상이야기

Oracle 스키마, 구조, 테이블정의서 Query

쿠카곰돌이 2016. 6. 26. 10:59
반응형



SELECT A.TABLE_NAME
        , (

           SELECT C.COMMENTS 

             FROM DBA_TAB_COMMENTS C 

           WHERE A.OWNER = C.OWNER AND A.TABLE_NAME = C.TABLE_NAME

          )  AS TABLE_COMMENTS
        ,B.COLUMN_ID AS COLUMN_NO
        ,B.COLUMN_NAME
        ,(

          SELECT D.COMMENTS 

          FROM DBA_COL_COMMENTS

          WHERE A.OWNER = D.OWNER 

          AND A.TABLE_NAME = D.TABLE_NAME 

          AND B.COLUMN_NAME = D.COLUMN_NAME

         ) AS COLUMN_COMMENTS
        , B.DATA_TYPE
        , CASE
            WHEN B.DATA_TYPE IN ('VARCHAR', 'VARCHAR2', 'CHAR') THEN
                    TO_CHAR(B.DATA_LENGTH)
            WHEN B.DATA_TYPE = 'NUMBER' THEN
                    B.DATA_PRECISION || ',' ||               

                    DECODE(B.DATA_SCALE,0,'0',B.DATA_SCALE)
                    ELSE ''
            END AS DATA_LENGTH
        ,B.NULLABLE
FROM DBA_TABLES A
JOIN DBA_TAB_COLUMNS

  ON A.OWNER = B.OWNER
 AND A.TABLE_NAME = B.TABLE_NAME
WHERE A.OWNER = 'ABUTW3'
AND A.TABLE_NAME LIKE 'AB_%' 
ORDER BY A.TABLE_NAME
,B.COLUMN_ID

반응형