본문 바로가기
ORACLE DBMS

IMPORT & EXPORT 유틸리티 사용하기 - table레벨

by Boggi 2024. 9. 10.
반응형

EXPORT 유틸리티는 데이터베이스 간 데이터 객체를 이동할 수 있는 방법을 제공
IMPORT 유틸리티는 export한 덤프 파일을 이용해서 데이터 객체를 오라클 데이터베이스에 입력

 

[ 과정 START ]

 

CTAS를 이용해서 테이블 생성

18:34:24 SYS@ORA19C>CREATE TABLE hr.emp AS SELECT * FROM hr.employees;

Table created.

 

107건의 데이터 존재

18:34:32 SYS@ORA19C>SELECT count(*) FROM hr.emp;

  COUNT(*)
----------
       107

 

emp table export하기(OS에서 해야 함)

[oracle@oracle19c ~]$ exp system/oracle file=hr_emp.dmp tables=hr.emp direct=y

 

hr.emp table drop하기

18:40:51 SYS@ORA19C>DROP TABLE hr.emp PURGE;

 

테이블이 존재하지 않는 것 확인

18:40:57 SYS@ORA19C>SELECT * FROM hr.emp;
SELECT * FROM hr.emp
                 *
ERROR at line 1:
ORA-00942: table or view does not exist

 

없어진 테이블 export받은 dump 파일을 이용해서 DB에 import하기

[oracle@oracle19c ~]$ imp system/oracle file=hr_emp.dmp fromuser=hr tables=emp

 

복원된 거 확인

18:44:55 SYS@ORA19C>SELECT count(*) FROM hr.emp;

  COUNT(*)
----------
       107

 

 

추가) 만약 TRUNCATE를 했다면?

19:48:44 SYS@ORA19C>Truncate table hr.emp;

 

data_only=y 파라미터를 이용해서 import 받자

[oracle@oracle19c ~]$ imp userid=system/oracle file=hr_emp.dmp fromuser=hr tables=emp data_only=y