반응형
1. SQL DEVELOPER에서 TABLE 추출

 

 

sqldeveloper에서 원하는 테이블을 컨트롤키 + 마우스 클릭하여 선택 
-> 마우스 우버튼 메뉴의 '익스포트' 선택 -> 데이터 익스포트의 형식을 insert로 선택 후 파일(F) 부분의 우측에 있는 [찾아보기] 버튼을 이용하여 다운로드 받을 경로 선택 후 저장할 파일명을 입력후 확장자(.sql)까지 붙여서 선택 후 확인 -> [다음]버튼 클릭 -> 원하는 테이블 목록과 컬럼이 모두 뜨는지 확인 후 [다음 ] -> [완료]하면 됨.

**반드시 원하는 경로에 파일이 저장되었는지 체크할 것

2. 추출한 TABLE.SQL 읽어오기

저장한 파일로 데이터베이스 얻어오는 방법 
2-1. sqldeveloper에서 하는 방법
저장한 파일의 쿼리문을 메모장으로 연 뒤 전체 복사하여 해당 계정의 워크시트에 붙여넣기 한 후 전체실행(F5)으로 처리하면 된다.

2-2. 명령프롬프트에서 실행하기
명령프롬프트 창 열기 (여는 순간 현재 작업 디렉토리 경로가 C:\Users\사용자계정명  으로 되어있다.) 
-> 윈도우키 + r 키  => cmd입력 후 엔터
-> sql파일이 저장된 위치까지 작업디렉토리를 변경해주어야 한다. 
C:\Users\사용자계정명>cd c:\~~파일이 저장된 경로(디렉토리명)까지 기술 후 엔터
(저장경로가 Download폴더인 경우 : cd C:\Users\사용자계정명폴더\Downloads
C:\Users\사용자계정명\Downloads > 현재 작업디렉토리가 이렇게 변경됨.
-> C:\Users\사용자계정명\Downloads > sqlplus "/as sysdba" --dba권한을 부여받은 계정으로 접근하면 됨.
-> SQL>@저장한파일명.sql 입력 후 엔터하면 완료됨.
**반드시 해당 파일이 저장된 경로까지 이동한 후 sqlplus로 접속해주어야 한다.

**expall.dmp 파일의 계정명 : ora_user
2-3. 데이터 베이스 dmp파일로 내보내기
-- 윈도우 명령프롬프트 창에서 실행할 것(sqlplus의 SQL 편집창 아님)
1. 해당 계정의 모든 테이블 데이터를 내보냄
C:\Users\사용자계정명>exp 사용자계정(되도록 대문자로)/비밀번호@SID file=다운로드하고자하는디렉토리경로포함\파일명.dmp 확장자까지 기술   

C:\Users\Hi>exp TEST/1111@xe file=c:\Users\Hi\Downloads\test.dmp

Export: Release 11.2.0.2.0 - Production on 목 1월 18 17:47:06 2024

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.


Connected to: Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
Export done in KO16MSWIN949 character set and AL16UTF16 NCHAR character set
server uses AL32UTF8 character set (possible charset conversion)

About to export specified users ...
. exporting pre-schema procedural objects and actions
. exporting foreign function library names for user TEST
. exporting PUBLIC type synonyms
. exporting private type synonyms
. exporting object type definitions for user TEST
About to export TEST's objects ...
. exporting database links
. exporting sequence numbers
. exporting cluster definitions
. about to export TEST's tables via Conventional Path ...
. . exporting table                           DEPT          4 rows exported
. . exporting table                         DEPT02          3 rows exported
. . exporting table                         DEPT03          4 rows exported
. . exporting table                         DEPT07          0 rows exported
. . exporting table                            EMP         12 rows exported
. . exporting table                          EMP01         12 rows exported
. . exporting table                          EMP02          0 rows exported
. . exporting table                          EMP08          0 rows exported
. exporting synonyms
. exporting views
. exporting stored procedures
. exporting operators
. exporting referential integrity constraints
. exporting triggers
. exporting indextypes
. exporting bitmap, functional and extensible indexes
. exporting posttables actions
. exporting materialized views
. exporting snapshot logs
. exporting job queues
. exporting refresh groups and children
. exporting dimensions
. exporting post-schema procedural objects and actions
. exporting statistics
Export terminated successfully without warnings.

-명령프롬프트에서 관리자권한으로 실행


2. 해당 계정이 속한 데이터베이스(xe)의 모든 계정의 모든 테이블 데이터를 내보냄
C:\Users\사용자계정명>exp 사용자계정(되도록 대문자로)/비밀번호@SID file=다운로드하고자하는디렉토리경로포함\파일명.확장자까지 기술   full=y
**full=y는 전체 모두 가져오거나 내보내기 하는 경우 사용하는 명령임

C:\Users\Hi>imp userid=TEST/1111@xe file=c:\Users\Hi\Downloads\test.dmp full=y

Import: Release 11.2.0.2.0 - Production on 목 1월 18 17:59:17 2024

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.


Connected to: Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production

Export file created by EXPORT:V11.02.00 via conventional path
import done in KO16MSWIN949 character set and AL16UTF16 NCHAR character set
import server uses AL32UTF8 character set (possible charset conversion)
. importing TEST's objects into TEST
IMP-00015: following statement failed because the object already exists:
 "CREATE TABLE "DEPT" ("DEPTNO" NUMBER(2, 0), "DNAME" VARCHAR2(14), "LOC" VAR"
 "CHAR2(13))  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 STORAGE(INITIAL 6"
 "5536 NEXT 1048576 MINEXTENTS 1 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DE"
 "FAULT)                     LOGGING NOCOMPRESS"
. . importing table                       "DEPT02"          3 rows imported
. . importing table                       "DEPT03"          4 rows imported
. . importing table                       "DEPT07"          0 rows imported
IMP-00015: following statement failed because the object already exists:
 "CREATE TABLE "EMP" ("EMPNO" NUMBER(4, 0), "ENAME" VARCHAR2(10), "JOB" VARCH"
 "AR2(9), "MGR" NUMBER(4, 0), "HIREDATE" DATE, "SAL" NUMBER(7, 2), "COMM" NUM"
 "BER(7, 2), "DEPTNO" NUMBER(2, 0))  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRAN"
 "S 255 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 FREELISTS 1 FREELIST "
 "GROUPS 1 BUFFER_POOL DEFAULT)                     LOGGING NOCOMPRESS"
. . importing table                        "EMP01"         12 rows imported
. . importing table                        "EMP02"          0 rows imported
. . importing table                        "EMP08"          0 rows imported
Import terminated successfully with warnings.


3. 해당 계정의 원하는 테이블만 데이터를 내보냄
C:\Users\사용자계정명>exp 사용자계정(되도록 대문자로)/비밀번호@SID tables=테이블이름,테이블이름 file=다운로드하고자하는디렉토리경로포함\파일명.확장자까지 기술   
C:\Users\사용자계정명>exp TEST/1111@xe tables=dept,emp file=c:\Users\hi\Downloads\dept.dmp

--파일을 내보낼 때는 c드라이브 바로 안에 쓰기가 안 될 수 있다(권한 문제)
--명령프롬프트로 실행할때 관리자권한으로 실행하면 c드라이브에 쓰기 가능

1. 동일한 계정의 데이터를 데이터베이스의 사용자계정으로 가져오기
C:\Users\사용자계정명>imp userid=데이터를넣을사용자계정명/비번@SID file=가져올파일이저장된디렉토리경로포함\파일명.확장자명 full=y
**full=y는 전체 모두 가져오거나 내보내기 하는 경우 사용하는 명령임

C:\Users\Hi>imp userid=TEST/1111@xe file=c:\Users\Hi\Downloads\expall.dmp fromuser=ora_user touser=TEST

Import: Release 11.2.0.2.0 - Production on 목 1월 18 18:08:44 2024

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.


Connected to: Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production

Export file created by EXPORT:V11.02.00 via conventional path

Warning: the objects were exported by ORA_USER, not by you

import done in KO16MSWIN949 character set and AL16UTF16 NCHAR character set
import server uses AL32UTF8 character set (possible charset conversion)
. importing ORA_USER's objects into TEST
. . importing table                     "CHANNELS"          5 rows imported
. . importing table                    "COUNTRIES"         23 rows imported
. . importing table                    "CUSTOMERS"      55500 rows imported
. . importing table                  "DEPARTMENTS"         27 rows imported
. . importing table                    "EMPLOYEES"        107 rows imported
. . importing table                  "JOB_HISTORY"         10 rows imported
. . importing table                         "JOBS"         19 rows imported
. . importing table              "KOR_LOAN_STATUS"        238 rows imported
. . importing table                     "PRODUCTS"         72 rows imported
Import terminated successfully without warnings.


2. 다른 계정의 데이터를 데이터베이스의 사용자계정으로 가져오기
C:\Users\사용자계정명>imp userid=데이터를넣을사용자계정명/비번@SID file=가져올파일이저장된디렉토리경로포함\파일명.확장자명 fromuser=가져올계정명 touser=넣어야할계정명
**fromuser, touser 사용시 full=y는 같이 사용할 수 없다.

C:\Users\Hi>sqlplus test/1111@xe

SQL*Plus: Release 11.2.0.2.0 Production on 목 1월 18 17:38:35 2024

Copyright (c) 1982, 2014, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production

SQL> CREATE USER SAMP IDENTIFIED BY 1111;

User created.

SQL> GRANT CONNECT, RESOURCE, DBA TO SAMP;

Grant succeeded.

SQL> CONN SAMP / 1111
Connected.
SQL> SHOW USER
USER is "SAMP"
SQL>
반응형

'[ORACLE]' 카테고리의 다른 글

[ORACLE] INDEX  (0) 2024.01.22
[ORACLE] JOIN  (0) 2024.01.19
[ORACLE] Transaction - COMMIT, SAVEPOINT, ROLLBACK, VIEW  (0) 2024.01.18
[ORACLE] 제약조건 CONSTRAINT  (0) 2024.01.17
[ORACLE] DDL - CREATE, ALTER, DROP, TRUNCATE, RENAME  (0) 2024.01.16

+ Recent posts