CREATE OR REPLACE DIRECTORY DATA_DIR AS 'M:\ORACLE';
SQL> create table external_table
2 (EMPNO NUMBER(4) ,
3 ENAME VARCHAR2(10),
4 JOB VARCHAR2(9),
5 MGR NUMBER(4),
6 HIREDATE CHAR(10),
7 SAL NUMBER(7, 2),
8 COMM NUMBER(7, 2),
9 DEPTNO NUMBER(2)
10 )
* 11 ORGANIZATION EXTERNAL*
* 12 ( type oracle_loader*
* 13 default directory data_dir*
* 14 access parameters*
* 15 ( fields terminated by ',' )*
* 16 location ('emp.dat')*
* 17 )*
18 /
테이블이 생성되었습니다.
LOAD DATA
INFILE 'emp.dat'
INTO TABLE emp
REPLACE
FIELDS TERMINATED BY ','
(EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO)
oracle>SQLLDR system/oracle EMP.CTL EXTERNAL_TABLE=GENERATE_ONLY
SQL*Loader: Release 10.2.0.3.0 - Production on 토 11월 15 03:11:54 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
CREATE TABLE "SYS_SQLLDR_X_EXT_EMP"
(
"EMPNO" NUMBER(4),
"ENAME" VARCHAR2(10),
"JOB" VARCHAR2(9),
"MGR" NUMBER(4),
"HIREDATE" DATE,
"SAL" NUMBER(7,2),
"COMM" NUMBER(7,2),
"DEPTNO" NUMBER(2)
)
ORGANIZATION external
(
TYPE oracle_loader
DEFAULT DIRECTORY SYS_SQLLDR_XT_TMPDIR_00000
ACCESS PARAMETERS
(
RECORDS DELIMITED BY NEWLINE CHARACTERSET KO16MSWIN949
BADFILE 'SYS_SQLLDR_XT_TMPDIR_00000':'emp.bad'
LOGFILE 'EMP.log_xt'
READSIZE 1048576
FIELDS TERMINATED BY "," LDRTRIM
REJECT ROWS WITH ALL NULL FIELDS
(
\-- 중략
)
)
location
(
'emp.dat'
)
)REJECT LIMIT UNLIMITED
SELECT * FROM EXTERNAL_TABLE where rownum < 10;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
\---------\- \---------\- \--------\- \---------\- \---------\- \---------\- \---------\- \---------\-
7369 SMITH CLERK 7902 1980/12/17 800 20
7499 ALLEN SALESMAN 7698 1981/02/20 1600 300 30
7521 WARD SALESMAN 7698 1981/02/22 1250 500 30
....
....
SQL> set autotrace traceonly
SQL> l
1\* SELECT * FROM EXTERNAL_TABLE where rownum < 1000
SQL> /
999 개의 행이 선택되었습니다.
Execution Plan
\---------------------------------------------------------\-
Plan hash value: 2646445939
\---------------------------------------------------------------------------------------------\-
\| Id \| Operation \| Name \| Rows \| Bytes \| Cost (%CPU)\| Time \|
\---------------------------------------------------------------------------------------------\-
\| 0 \| SELECT STATEMENT \| \| 999 \| 89910 \| 5 (0)\| 00:00:01 \|
\|* 1 \| COUNT STOPKEY \| \| \| \| \| \|
\| 2 \| EXTERNAL TABLE ACCESS FULL\| EXTERNAL_TABLE \| 999 \| 89910 \| 5 (0)\| 00:00:01 \|
\---------------------------------------------------------------------------------------------\-
Predicate Information (identified by operation id):
\--------------------------------------------------\-
1 - filter(ROWNUM<1000)
Statistics
\---------------------------------------------------------\-
17 recursive calls
0 db block gets
44 consistent gets
0 physical reads
0 redo size
50323 bytes sent via SQL*Net to client
1126 bytes received via SQL*Net from client
68 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
999 rows processed
방법 | CPU | 경과 | 행 |
---|---|---|---|
SQLLDR direct=true | 29 | 42 | 1833792 |
외부 테이블 INSERT /*\+ APPEND \*/ | 33 | 38 | 1833792 |
외부테이블 CREATE TABLE AS SELECT | 32 | 37 | 1833792 |
외부테이블 INSERT(Convential Path) | 42 | 130 | 1833792 |
SQLLDR(Conventional Path) | 50 | 410 | 1833792 |
SQL> alter table external_table parallel 4;
테이블이 변경되었습니다.
SQL> create table emp4 as select * from external_table;
테이블이 생성되었습니다.
SQL> r
1\* select sid,username,EVENT,ownerid from v$session where ownerid\!='2147483644'
SID USERNAME EVENT OWNERID
\---------\- \-----------------------------\- \-----------------------------\- \---------\-
144 SYSTEM PX Deq Credit: send blkd 65688
145 SYSTEM PX Deq: Execution Msg 65688
150 SYSTEM PX Deq: Execution Msg 65688
159 SYSTEM PX Deq: Execution Msg 65688
SQL> merge into EMP e1
2 using *EXTERNAL_TABLE e2*
3 on ( e2.empno = e1.empno )
4 when matched then
5 update set e1.sal = e2.sal
6 when not matched then
7 insert (empno, ename, job, mgr, hiredate, sal, comm, deptno)
8 values ( e2.empno, e2.ename, e2.job,
e2.mgr, e2.hiredate, e2.sal, e2.comm, e2.deptno )
9 /
14 rows merged
ORA> create table external_table
2 (EMPNO NUMBER(4) ,
3 ENAME VARCHAR2(10),
4 JOB VARCHAR2(9),
5 MGR NUMBER(4),
6 HIREDATE DATE,
7 SAL NUMBER(7, 2),
8 COMM NUMBER(7, 2),
9 DEPTNO NUMBER(2)
10 )
11 ORGANIZATION EXTERNAL
12 ( type oracle_loader
13 default directory data_dir
14 access parameters
15 (
16 records delimited by newline
17 *badfile data_dir:emp_external_table*
18 fields terminated by ','
19 )
20 location ('emp.dat')
21 )
22 reject limit unlimited
23 /
SQL> create table emp_external_table_bad
2 ( text1 varchar2(4000) ,
3 text2 varchar2(4000) ,
4 text3 varchar2(4000)
5 )
6 organization external
7 (type oracle_loader
8 default directory data_dir
9 access parameters
10 (
11 records delimited by newline
12 fields
13 missing field values are null
14 ( text1 position(1:4000),
15 text2 position(4001:8000),
16 text3 position(8001:12000)
17 )
18 )
19 location ('emp_external_table.bad')
20 )
21 /
SQL> select count(*) from emp_external_table_bad;
COUNT(*)
\---------\-
25722
SQL> select * from emp_external_table_bad where rownum=1;
TEXT1
\---------------------------------------------------------------------------------------------------\-
TEXT2
\---------------------------------------------------------------------------------------------------\-
TEXT3
\---------------------------------------------------------------------------------------------------\-
7369,SMITH,CLERK,7902,1980/12/17,800,,20
- 강좌 URL : http://www.gurubee.net/lecture/3568
- 구루비 강좌는 개인의 학습용으로만 사용 할 수 있으며, 다른 웹 페이지에 게재할 경우에는 출처를 꼭 밝혀 주시면 고맙겠습니다.~^^
- 구루비 강좌는 서비스 제공을 위한 목적이나, 학원 홍보, 수익을 얻기 위한 용도로 사용 할 수 없습니다.