카테고리 없음

오라클 SQL- Data Pump를 이용하여 External table과 Dump파일 만들기

해피밀세트 2020. 2. 12. 17:51
반응형

 

Data Pump 란?

- 바이너리 형식으로 구성됨
- write, read 둘다 할 수 있음 (oracle loader은 read만 할 수 있다.)
- 서브쿼리절을 기반으로 extnal 테이블을 생성하고
  dump파일에 데이터를 넣고 다시 읽어들인다.
- external 테이블을 조회하면 location에 있는 dump파일을 엑세스하는것이다.
- external 테이블을 drop하면 스토리지가 없기때문에 flashback 없다.
- 때문에 실수로 drop할때를 대비해서 작성한 코드를 백업해두자!

 


 

Data Pump를 이용하여  External table과 Dump파일 만들기

 

1) 오라클 SQL Developer에서 HR SESSION을 연다.

 

2) 디렉토리를 확인한다.

 > select * from all_directories;

 

3) External table과 Dump 파일을 한번에 생성한다.

> create table emp_dump 
   organization external
   (type oracle_datapump
    default directory data_dir
    location('emp_datapump.dump'))
   as
   select employee_id, last_name, salary, hire_date, department_id
   from employees;

 

[코드 설명]

> create table emp_dump -------------------> 테이블 생성 명령 및 테이블 이름 지정
   organization external ----------------------> external 테이블 조직
   (type oracle_datapump --------------------> Oracle의 Datapump 프로그램 사용
    default directory data_dir -----------------> 설정한 디렉토리의 이름
    location('emp_datapump.dump')) ---------> '파일이름.dump'으로 dump파일이 생성되고 다음부터 이파일을 호출
   as 
   select employee_id, last_name, salary, hire_date, department_id 
   from employees; ----------------------------> 색칠된 이 구문은 처음 파일 만들때만 실행됨.

 

테이블 생성이 완료되면 아래와 같은 구문이 출력된다.

 

4) 확인하기

> select * from emp_dump;

 

# 별칭을 사용한 방법

create table emp_dump(id,name,sal,hire,dept_id) ----->별칭을 이렇게 써도 된다.
organization external
(type oracle_datapump
 default directory data_dir
 location('emp_200212.dump')) ------------------------> 보통 dump파일 이름을 날짜로 쓴다.
as
select employee_id, last_name, salary, hire_date, department_id
from employees;

 

# 이미 Dump 파일이 만들어져 있다면?

서브쿼리절을 사용할 필요가 없으니 삭제하고 사용 가능하다.

create table emp_dump(id number,name varchar2(30), sal number,
                                hire date, dept_id number) -------------> 여기에 데이터 타입 적어놓기
organization external
(type oracle_datapump
 default directory data_dir
 location('emp_200212.dump'));

 

반응형