오라클 테이블 스키마 가져오는 쿼리
오라클 테이블 스키마 가져오는 쿼리
오라클 테이블 스키마를 가져와 테이블 스키마 정의서를 만들 때 사용하던 쿼리를 소개한다.
오라클 사용자와 테이블명에 대한 PK, FK, Column name, Data type, Data length, Nullable, data default, Comments 등의 정보를 가져오는 쿼리이다.
-- show schema of a table with INFO as ( select 'USER_NAME' as username ,'ADM_USER' as usertable from dual ), PK as ( select c.column_name ,case when a.constraint_type = 'R' then 'Y' else '' end as column_fk from sys.user_cons_columns c, sys.user_constraints a, INFO u where a.owner = c.owner and a.table_name = c.table_name and a.constraint_name = c.constraint_name and a.constraint_type in ('P','R') and a.table_name = u.usertable and a.OWNER = u.username ) select PK ,FK ,column_name ,data_type ,data_length ,nullable ,data_default ,comments from ( SELECT case when length(p.column_name) > 0 then 'PK' else ' ' end as PK ,p.column_fk as FK ,c.column_name ,c.data_type ,case when c.data_type = 'VARCHAR2' then to_char(data_length) when c.data_type = 'DATE' or c.data_type = 'FLOAT' or c.data_type = 'INTEGER' or c.data_type = 'BLOB' then '' when c.data_type = 'NUMBER' then (case when data_precision is null then '' when data_scale = 0 then to_char(data_precision) else to_char(data_precision) || ',' || to_char(data_scale) end ) else (case when data_precision is null then '' when data_scale = 0 then to_char(data_precision) else to_char(data_precision) || ',' || to_char(data_scale) end ) end as data_length ,c.COLUMN_ID ,c.NULLABLE ,c.data_default ,s.comments FROM USER_TAB_COLUMNS c, PK p, INFO u, USER_COL_COMMENTS s WHERE c.TABLE_NAME = u.usertable and c.column_name = p.column_name(+) and c.table_name = s.table_name and c.COLUMN_NAME = s.column_name ) order by column_id
아래는 오라클의 테이블(Table), 뷰(View), 패키지(Package), 인덱스(Index), 프로시저(Procedure), 펑션(Function), 트리거(Trigger) 와 같은 오라클 오브젝트에 대한 데이터베이스 정보를 가져오는 방법에 대해서 소개한다.
Tables
오라클 테이블스페이별 테이블명 가져오는 쿼리
This is a query to get all Oracle tables for the tablespace
select * --table_name, ... from user_tables where tablespace_name = 'TABLESPACE_NAME' order by table_name
Views
오라클 사용자별 뷰(View) 가져오는 쿼리
This is a query to get all Oracle views for the current user
select * --VIEW_NAME, OWNER, ... from ALL_VIEWS and OWNER = 'OWNER_NAME'
Packages
오라클 사용자별 패키지(Packages) 가져오는 쿼리
This is a query to get all Oracle packages for the current user
select * --OBJECT_NAME, OWNER, ... from ALL_OBJECTS where upper(OBJECT_TYPE) = 'PACKAGE' and OWNER = 'OWNER_NAME'
Procedures
오라클 사용자별 프로시저(Procedure) 가져오는 쿼리
This is a query to get all Oracle procedures for the current user.
select * --OBJECT_NAME, OWNER, ... from ALL_OBJECTS where upper(OBJECT_TYPE) = 'PROCEDURE' and OWNER = 'OWNER_NAME'
Procedure Columns
오라클 프로시저 내 컬럼 가져오는 쿼리
This is a query to get the columns in an Oracle procedure
select * --OWNER, OBJECT_NAME, ARGUMENT_NAME, DATA_TYPE, IN_OUT, ... from ALL_ARGUMENTS order by OWNER, OBJECT_NAME, SEQUENCE
Functions
오라클 사용자별 펑션(Function) 가져오는 쿼리
This is a query to get all Oracle functions for the current user
select * --OBJECT_NAME, OWNER, ... from ALL_OBJECTS where upper(OBJECT_TYPE) = upper('FUNCTION') and OWNER = 'OWNER_NAME'
Triggers
오라클 사용자별 트리거(Trigger) 가져오는 쿼리
This is a query to get all Oracle triggers for the current user
select * --TRIGGER_NAME, OWNER, ... from ALL_TRIGGERS where OWNER = 'OWNER_NAME'
Indexes
오라클 사용자별 인덱스(Index) 가져오는 쿼리
This is a query to get all Oracle indexes for the current user
select * --INDEX_NAME, TABLE_NAME, TABLE_OWNER, ... from ALL_INDEXES where OWNER = 'OWNER_NAME'
2013/12/03 - [Note/Database] - 오라클 Tablespace 생성, User 생성 방법
2013/10/25 - [Note/Database] - Oracle 오라클 소수점 앞에 0 붙이기
댓글
이 글 공유하기
다른 글
-
오라클 월별 일자 구하기 CONNECT BY LEVEL
오라클 월별 일자 구하기 CONNECT BY LEVEL
2015.05.20오라클 월별 일자 구하기 CONNECT BY LEVEL select START_DTE + LEVEL MON_DTE from ( select to_date('201505010000', 'YYYYMMDDHH24MISS') - 1 START_DTE ,add_months(to_date('201505010000', 'YYYYMMDDHH24MISS'), 1) - 1 END_DTE from DUAL ) connect by LEVEL -
PL/SQL Developer로 프로시저(Procedure) Debugging 하는 방법
PL/SQL Developer로 프로시저(Procedure) Debugging 하는 방법
2014.09.19PL/SQL Developer로 프로시저(Procedure) Debugging 하는 방법 1. 접속한 세션에 디버깅 권한 주기 grant debug connect session to '아이디'; grant debug any procedure to '아이디'; 위 과정이 끝났다면 PL/SQL Developer를 이용해 프로시저나 패키지내 펑션을 디버깅 한다. 프로시저(또는 패키지)를 선택하고 마우스 오른쪽 버튼을 눌러 Add Debug information 에 체크한다. 간혹 체크가 되어 있어도 디버깅이 되지 않는 경우가 있다. 이런 경우에는 체크가 되어 있더라도 다시 Add debug information을 체크한다. 패키지의 경우 Spec & Body로 나뉘어 있으므로 View Spec & Body를 … -
오라클(Oracle) 년도별 주차 구하는 방법, 월별 주차 구하는 방법
오라클(Oracle) 년도별 주차 구하는 방법, 월별 주차 구하는 방법
2014.08.12오라클(Oracle) 년도별 주차 구하는 방법, 월별 주차 구하는 방법 with ISO as ( select to_char(WEEK_START, 'YYYY-MM-DD') WEEK_START ,to_char(WEEK_END, 'YYYY-MM-DD') WEEK_END ,to_char(WEEK_START, 'WW') WEEK_OF_YEAR_ISO ,to_char(WEEK_START, 'W') WEEK_OF_MONTH from ( select trunc(START_DT + LEVEL, 'D') WEEK_START ,trunc(START_DT + LEVEL, 'D') + 6 WEEK_END from ( select to_date('20140101', 'YYYYMMDD') - 1 START_DT ,to_date('… -
DB2 날짜 구하기, 주차 구하기(재귀함수 recursive function 이용)
DB2 날짜 구하기, 주차 구하기(재귀함수 recursive function 이용)
2014.02.19DB2 월별 날짜(일수) 구하기, 주차 구하기(재귀함수 recursive function 이용) 1. 월별 날짜 구하는 방법, 월별 일수 구하는 방법 WITH DATE_RANGE(DT, WEEK) AS ( SELECT DATE('2011-01-01') AS DT ,WEEK_ISO('2011-01-01') AS WEEK FROM SYSIBM.SYSDUMMY1 UNION ALL SELECT DATE(DT) + 1 DAY AS DT ,WEEK_ISO(DATE(DT) + 1 DAY) AS WEEK FROM DATE_RANGE WHERE DT < DATE('2011-12-31') ) SELECT DT ,WEEK FROM DATE_RANGE 2. 월별 주차 구하는 방법 WITH DATE_RANGE(DT, WEEK)…
댓글을 사용할 수 없습니다.