사용자 도구

사이트 도구


dbms:oracle:admin:oraclequerytip

Oracle SQL Tips

Table 생성시기를 알아오는 쿼리

SQL> SELECT OWNER,OBJECT_NAME,CREATED
FROM DBA_OBJECTS
WHERE CREATED > '2006-08-31' AND OWNER NOT IN ('SYS') AND OBJECT_TYPE = 'TABLE'
ORDER BY OWNER,CREATED ASC;

전체테이블 TRUNCATE하는 쿼리 만들기

SQL> SELECT 'truncate table '||table_name||';' FROM user_tables
WHERE table_name NOT IN ('TEMPLATE_XML','QUESTION_XML')
ORDER BY table_name ASC;

테이블 정의를 출력해주는 쿼리

SQL> SELECT TC.TABLE_NAME
	   ,TCOMMENT.COMMENTS AS KOR_TNAME
	   ,TC.COLUMN_NAME
	   ,CCOMMENT.COMMENTS AS KOR_CNAME
	   ,TC.DATA_TYPE||'('||TC.DATA_LENGTH||')'
	   ,DECODE(PK.CT,'P','PK','') AS PK
	   ,DECODE(TC.NULLABLE,'N','NOT NULL','') AS NOT_NULL
	   ,TC.DATA_DEFAULT,'' AS ETC
FROM USER_TAB_COLUMNS TC 
	 ,USER_COL_COMMENTS CCOMMENT 
	 ,USER_TAB_COMMENTS TCOMMENT
	 ,(
	   	SELECT CCOL.TABLE_NAME,CCOL.COLUMN_NAME,UC.CONSTRAINT_TYPE CT
	 	FROM USER_CONS_COLUMNS CCOL,USER_CONSTRAINTS UC
		WHERE CCOL.CONSTRAINT_NAME = UC.CONSTRAINT_NAME
			  AND CCOL.TABLE_NAME = UC.TABLE_NAME
			  AND UC.CONSTRAINT_TYPE = 'P'
	   ) PK
WHERE TC.TABLE_NAME = TCOMMENT.TABLE_NAME
	 AND TC.TABLE_NAME = CCOMMENT.TABLE_NAME
	 AND TC.COLUMN_NAME = CCOMMENT.COLUMN_NAME
	 AND TC.TABLE_NAME = PK.TABLE_NAME(+)
	 AND TC.COLUMN_NAME = PK.COLUMN_NAME(+)
	 AND TC.TABLE_NAME LIKE 'TB_%' AND TC.TABLE_NAME NOT LIKE '%_HIST'
	 AND TCOMMENT.TABLE_TYPE = 'TABLE'
ORDER BY TC.TABLE_NAME,TC.COLUMN_ID;
dbms/oracle/admin/oraclequerytip.txt · 마지막으로 수정됨: 2007/01/28 14:32 저자 starlits