--테이블 정의서 추출하기
SELECT A.TABLE_NAME, REGEXP_SUBSTR(B.COMMENTS,'[^|]+',1,1) AS CMT
FROM USER_TABLES A, USER_TAB_COMMENTS B
WHERE B.TABLE_NAME = A.TABLE_NAME
ORDER BY A.TABLE_NAME;
-- 컬럼 정의서 추출하기
SELECT TBL.TABLE_NAME , TCM.COMMENTS , TBL.TABLESPACE_NAME , TCL.COLUMN_ID
, TCL.COLUMN_NAME
, CCM.COMMENTS
, DATA_TYPE
, DATA_LENGTH
/*
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
*/
,DECODE(NULLABLE , 'N' , 'N' , 'Y') AS NOTNULL
--, DECODE(CON.KEY, 'PK','P', 'FK','F','') PK
, DECODE(CON.KEY, 'PK','P', '') PK
, DATA_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 , '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
;
'닷컴's_열공 > Database' 카테고리의 다른 글
[oracle] Nologging 과 insert apend (0) | 2022.11.10 |
---|---|
오라클 db link 스크립트 (0) | 2022.11.09 |
오라클 프로시져 호출하기 OUT이 있는 경우 (0) | 2020.03.18 |
Oracle - Split 방식, 문자열의 세로 분리 - 참조 (0) | 2019.03.20 |
법인등록번호,사업자,주민등록번호 유효성체크 (0) | 2019.02.07 |