이 영역을 누르면 첫 페이지로 이동
필린(FILLIN) - 느낌을 담은 사진 블로그의 첫 페이지로 이동

필린(FILLIN) - 느낌을 담은 사진

페이지 맨 위로 올라가기

필린(FILLIN) - 느낌을 담은 사진

느낌을 담은 사진

오라클 테이블 스키마 가져오는 쿼리

  • 2014.09.18 09:41
  • Note/Database


오라클 테이블 스키마 가져오는 쿼리


오라클 테이블 스키마를 가져와 테이블 스키마 정의서를 만들 때 사용하던 쿼리를 소개한다.

오라클 사용자와 테이블명에 대한 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' 
	



2014/08/12 - [Note/Database] - 오라클(Oracle) 년도별 주차 계산, 월별 주차 구하기, week of year, week of month


2013/12/03 - [Note/Database] - 오라클 Tablespace 생성, User 생성 방법


2013/10/25 - [Note/Database] - Oracle 오라클 소수점 앞에 0 붙이기


저작자표시 비영리 변경금지 (새창열림)

댓글

이 글 공유하기

  • 구독하기

    구독하기

  • 카카오톡

    카카오톡

  • 라인

    라인

  • 트위터

    트위터

  • Facebook

    Facebook

  • 카카오스토리

    카카오스토리

  • 밴드

    밴드

  • 네이버 블로그

    네이버 블로그

  • Pocket

    Pocket

  • Evernote

    Evernote

다른 글

  • 오라클 월별 일자 구하기 CONNECT BY LEVEL

    오라클 월별 일자 구하기 CONNECT BY LEVEL

    2015.05.20
  • PL/SQL Developer로 프로시저(Procedure) Debugging 하는 방법

    PL/SQL Developer로 프로시저(Procedure) Debugging 하는 방법

    2014.09.19
  • 오라클(Oracle) 년도별 주차 구하는 방법, 월별 주차 구하는 방법

    오라클(Oracle) 년도별 주차 구하는 방법, 월별 주차 구하는 방법

    2014.08.12
  • DB2 날짜 구하기, 주차 구하기(재귀함수 recursive function 이용)

    DB2 날짜 구하기, 주차 구하기(재귀함수 recursive function 이용)

    2014.02.19
다른 글 더 둘러보기

정보

필린(FILLIN) - 느낌을 담은 사진 블로그의 첫 페이지로 이동

필린(FILLIN) - 느낌을 담은 사진

  • 필린(FILLIN) - 느낌을 담은 사진의 첫 페이지로 이동

검색

메뉴

  • Home
  • Guest Book
  • Tag

카테고리

  • 분류 전체보기 (597) N
    • His Story (136)
      • Korea (94)
      • Australia (39)
      • Japan (2)
      • Essay (1)
    • Photography (121)
      • Concept Story (5)
      • Landscape (52)
      • Planet (5)
      • Feeling (23)
      • Macro (20)
      • Model (12)
      • Photo Contest (4)
    • Reviewing (141) N
      • Electronics (5)
      • Photo & Imaging (23) N
      • Testing a wine (45)
      • Arts (3)
      • Cafe (11)
      • Foods (39)
      • Etc. (15)
    • Note (197)
      • 리시드(Reseed) (1)
      • Photoshop (10)
      • 촬영장소 (1)
      • SongWriting (1)
      • Tip & Tech. (52)
      • Database (10)
      • Dev (19)
      • Mobile Game (1)
      • Drawing (24)
      • Network (7)
      • iOS , OS X (28)
      • Web (8)
      • Car (19)
      • Event (5)
      • Photo Contest schedule (11)

태그

  • SNCT
  • 와인
  • 색칠공부
  • 티스토리챌린지
  • 송도
  • 오막포
  • 선광신컨테이너터미널
  • 오블완

인기 글

나의 외부 링크

  • 느낌을 담은 사진, 필린(FILLIN)
  • 네이버 블로그 이웃으로 추가
  • 필린 그라피
  • Instagram for Fillin
  • Facebook for Fillin
  • 500px
  • 디지털카메라매거진
  • 캐논코리아 블로그
  • 영상디자인 연구실
  • 산들산들
  • 디카 허브
  • Point of the day
  • 단적비의 찰칵하는 순간의 설레임
  • 파란오레오
  • Mute's Blog
  • Digital Photography Review
  • LensTip.com - lens review
  • 루비의 정원
  • 신나는 디지털놀이터 | 팝코넷
  • 프라치노 공간 (스킨)
  • Google Adsense
  • Google Analytics
  • 구글 서치
  • W생활정보
  • SWEV

정보

Fillin(필린)의 필린(FILLIN) - 느낌을 담은 사진

필린(FILLIN) - 느낌을 담은 사진

Fillin(필린)

블로그 구독하기

  • 구독하기
  • 네이버 이웃 맺기
  • RSS 피드

방문자

  • 전체 방문자
  • 오늘
  • 어제

티스토리

  • 티스토리 홈
  • 이 블로그 관리하기
  • 글쓰기
Powered by Tistory / Kakao. Copyright © Fillin(필린).

티스토리툴바