SELECT TBL.TABLE_NAME , TCM.COMMENTS , TBL.TABLESPACE_NAME , TCL.COLUMN_ID , TCL.COLUMN_NAME , CASE WHEN TCL.DATA_TYPE = 'VARCHAR2' OR TCL.DATA_TYPE = 'CHAR' OR TCL.DATA_TYPE = 'NUMBER' THEN TCL.DATA_TYPE || '(' || DATA_LENGTH || ')' ELSE TCL.DATA_TYPE END AS DATA_TYPE , CON.KEY , DECODE(NULLABLE , 'N' , 'NOT NULL' , '') AS NOTNULL , DATA_DEFAULT , CCM.COMMENTS 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 , 'F' , 1 , 0)) > 0 THEN 'PK,FK' WHEN SUM(DECODE(CONSTRAINT_TYPE , 'P' , 1 , 0)) > 0 THEN 'PK' WHEN SUM(DECODE(CONSTRAINT_TYPE , 'F' , 1 , 0)) > 0 THEN 'FK' ELSE '' END AS KEY , SUM(DECODE(CONSTRAINT_TYPE , 'C' , 0 , 'P' , 0 , 'F' , 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(+) ORDER BY TBL.TABLE_NAME , COLUMN_ID
출처 : http://pompsky.blog.me/60051648162
'DB > Oracle' 카테고리의 다른 글
오라클 유저 비밀번호 변경 (0) | 2013.09.26 |
---|---|
' 홑따옴표 처리 (0) | 2013.09.04 |
update select문 (0) | 2013.03.21 |
날짜변환 (0) | 2013.02.01 |