Database/ORACLE

컬럼 정보 확인

타카스 류지 2015. 2. 24. 11:48
SELECT
     BB.OWNER                               AS OWNER
    ,BB.TABLE_NAME                          AS TABLE_ID
    ,GG.COMMENTS                            AS TABLE_NAME
    ,BB.COLUMN_ID+1                         AS COLUMN_NO
    ,BB.COLUMN_NAME                         AS COLUMN_ID
    ,AA.COMMENTS                            AS COLUMM_NAME
    ,BB.DATA_TYPE                           AS DATA_TYPE
    ,DECODE(BB.DATA_TYPE, 'NUMBER', BB.DATA_PRECISION, BB.DATA_LENGTH) AS DATA_LENGTH
    ,BB.DATA_SCALE                          AS DATA_SCALE
    ,DECODE(CC.COLUMN_NAME, '', '', 'Y')    AS PK
    ,DECODE(BB.NULLABLE, 'Y', '', 'Y')      AS NULLABLE
    ,BB.DATA_DEFAULT                        AS DEFAULT_VALUE
    ,SUBSTR(EE.CONSTRAINT_NAME, 12, 7)      AS FK_ID
    ,FF.TABLESPACE_NAME                     AS TS_NAME
    ,FF.NUM_ROWS                            AS ROW_CNT
    ,DD.CREATED                             AS CRE_DATE
    ,DD.LAST_DDL_TIME                       AS UPT_DATE
FROM ( SELECT * FROM    ALL_COL_COMMENTS  ) AA,
 ( SELECT * FROM    ALL_TAB_COLUMNS   ) BB,
 ( SELECT * FROM    ALL_CONS_COLUMNS    WHERE CONSTRAINT_NAME LIKE 'PK%') CC,
 ( SELECT * FROM    ALL_OBJECTS         WHERE OBJECT_TYPE = 'TABLE' AND OWNER = '계정명' ) DD,
 ( SELECT * FROM    ALL_CONS_COLUMNS    WHERE CONSTRAINT_NAME LIKE 'FK%') EE,
 ( SELECT * FROM    ALL_TABLES          WHERE OWNER = '계정명') FF,
 ( SELECT * FROM    ALL_TAB_COMMENTS    WHERE OWNER = '계정명') GG
WHERE 1=1
    AND   AA.OWNER          = BB.OWNER
    AND   AA.TABLE_NAME     = BB.TABLE_NAME
    AND   AA.COLUMN_NAME    = BB.COLUMN_NAME
    AND   AA.OWNER          = CC.OWNER(+)
    AND   AA.TABLE_NAME     = CC.TABLE_NAME(+)
    AND   AA.COLUMN_NAME    = CC.COLUMN_NAME(+)
    AND   AA.OWNER          = DD.OWNER
    AND   AA.TABLE_NAME     = DD.OBJECT_NAME
    AND   AA.OWNER          = EE.OWNER(+)
    AND   AA.TABLE_NAME     = EE.TABLE_NAME(+)
    AND   AA.COLUMN_NAME    = EE.COLUMN_NAME(+)
    AND   AA.TABLE_NAME     = FF.TABLE_NAME(+)
    AND   AA.TABLE_NAME     = GG.TABLE_NAME(+)
    -- AND   SUBSTR(AA.TABLE_NAME,0,2) = '구분자'  <-- 테이블이 많을시에 구분 조건
    AND   AA.TABLE_NAME LIKE '테이블 명'
ORDER BY AA.TABLE_NAME, BB.COLUMN_ID