2011년 7월 25일 월요일

테이블 내역서 만들기


select TBL.TABLE_NAME,
  TCM.COMMENTS,
  TBL.TABLESPACE_NAME,
  TCL.COLUMN_ID "No",
  TCL.COLUMN_NAME "컬럼ID",
  CCM.COMMENTS "컬럼명",
  TCL.DATA_TYPE as "데이타타입",
  case when TCL.DATA_TYPE = 'VARCHAR2' or TCL.DATA_TYPE = 'CHAR'
           then '' || DATA_length || ''
       when TCL.DATA_TYPE = 'NUMBER' and data_precision > 0 and data_scale > 0
          then '' || data_precision || ',' || data_scale || ''
       when TCL.DATA_TYPE = 'NUMBER' and data_precision > 0
          then '' || data_precision || ''
       when TCL.DATA_TYPE = 'NUMBER'
          then ''
       else ''
  end as  "데이타길이",
  case
    when TCL.DATA_TYPE = 'VARCHAR2' or TCL.DATA_TYPE = 'CHAR' then data_length
    --when TCL.DATA_TYPE = 'NUMBER' and data_precision > 0 and data_scale > 0 then  TCL.DATA_TYPE || '(' || data_precision || ',' || data_scale || ')'
    --when TCL.DATA_TYPE = 'NUMBER' and data_precision > 0 then TCL.DATA_TYPE || '(' || data_precision || ')'
    --when TCL.DATA_TYPE = 'NUMBER' then TCL.DATA_TYPE || '()'
    else data_length
  end as  "데이타길이",
  decode(NULLABLE , 'N' , 'N' , 'Y') AS "NULL" ,
  CON.KEY ,
  DATA_DEFAULT "Default",
  '' "비고"
from USER_TABLES TBL,
  USER_TAB_COMMENTS TCM,
  USER_TAB_COLUMNS TCL,
  USER_COL_COMMENTS CCM,
  (
    select CCL.TABLE_NAME ,
      COLUMN_NAME ,
      case when sum(decode(CONSTRAINT_TYPE , 'P' , 1 , 0)) > 0
      and sum(decode(CONSTRAINT_TYPE , 'R' , 1 , 0)) > 0 then 'PK,FK' when sum(decode(CONSTRAINT_TYPE , 'P' , 1 , 0)) > 0 then 'PK' when sum(decode(CONSTRAINT_TYPE , 'R' , 1 , 0)) > 0 then 'FK' else '' end as KEY ,
      sum(decode(CONSTRAINT_TYPE , 'C' , 0 , 'P' , 0 , 'R' , 0 , 1)) as CCC
    from USER_CONS_COLUMNS CCL ,
      USER_CONSTRAINTS CNS
    where CCL.CONSTRAINT_NAME = CNS.CONSTRAINT_NAME
    group by CCL.TABLE_NAME , COLUMN_NAME ) CON
where TBL.TABLE_NAME = TCM.TABLE_NAME
  and TBL.TABLE_NAME = TCL.TABLE_NAME
  and TCL.TABLE_NAME = CCM.TABLE_NAME
  and TCL.COLUMN_NAME = CCM.COLUMN_NAME
  and TCL.TABLE_NAME = CON.TABLE_NAME(+)
  and TCL.COLUMN_NAME = CON.COLUMN_NAME(+)
  AND TBL.TABLE_NAME IN ('TB_COM_ACCESS_ALLUSER_STAT',
      'TB_COM_ACCESS_BATCH',
      'TB_COM_ACCESS_BATCHLOG',
      'TB_COM_ACCESS_LOGIN_STAT',
      'TB_COM_ACCESS_MENU_STAT',
      'TB_COM_ACCESS_USE_STAT')
order by TBL.TABLE_NAME , COLUMN_ID

댓글 없음:

댓글 쓰기