티스토리 뷰
이번에 비교점 조사가 있어 전체적으로 테스트해 봤다. 나혼자한건 아니고 ;;
DB2
IBM의 DB2는 자체 import, export로 지원한다.
db2 => select * from employee
EMPNO FIRSTNME MIDINIT LASTNAME WORKDEPT PHONENO HIREDATE JOB EDLEVEL SEX BIRTHDATE SALARY BONUS COMM
------ ------------ ------- --------------- -------- ------- ---------- -------- ------- --- ---------- ----------- ----------- -----------
000010 CHRISTINE I HAAS A00 3978 1995-01-01 PRES 18 F 1963-08-24 152750.00 1000.00 4220.00
000020 MICHAEL L THOMPSON B01 3476 2003-10-10 MANAGER 18 M 1978-02-02 94250.00 800.00 3300.00
42 record(s) selected.
- myfile.del의 구조(CSV)
"000010";"CHRISTINE";"I";"HAAS";"A00";"3978";19950101;"PRES ";18;"F";19630824;+0152750.00;+0001000.00;+0004220.00
"000020";"MICHAEL";"L";"THOMPSON";"B01";"3476";20031010;"MANAGER ";18;"M";19780202;+0094250.00;+0000800.00;+0003300.00
db2 => create table employee1 as (select * from employee) with no data
DB20000I The SQL command completed successfully.
db2 => import from myfile.del of del modified by coldel; insert into employee1
SQL3109N The utility is beginning to load data from file "myfile.del".
SQL3110N The utility has completed processing. "42" rows were read from the
input file.
SQL3221W ...Begin COMMIT WORK. Input Record Count = "42".
SQL3222W ...COMMIT of any database changes was successful.
SQL3149N "42" rows were processed from the input file. "42" rows were
successfully inserted into the table. "0" rows were rejected.
Number of rows read = 42
Number of rows skipped = 0
Number of rows inserted = 42
Number of rows updated = 0
Number of rows rejected = 0
Number of rows committed = 42
db2 => select * from employee1
EMPNO FIRSTNME MIDINIT LASTNAME WORKDEPT PHONENO HIREDATE JOB EDLEVEL SEX BIRTHDATE SALARY BONUS COMM
------ ------------ ------- --------------- -------- ------- ---------- -------- ------- --- ---------- ----------- ----------- -----------
000010 CHRISTINE I HAAS A00 3978 1995-01-01 PRES 18 F 1963-08-24 152750.00 1000.00 4220.00
000020 MICHAEL L THOMPSON B01 3476 2003-10-10 MANAGER 18 M 1978-02-02 94250.00 800.00 3300.00
- demo1.ctl
LOAD DATA
INFILE *
INTO TABLE dept
FIELDS TERMINATED BY ','
(
deptno
,dname
,loc
)
BEGINDATA
10,ACCOUNTING,NEW YORK
20,RESEARCH,DALLAS
30,SALES,CHICAGO
40,OPERATIONS,BOSTON
이 ctl파일 구조는 많은 DBMS에서 사용하니 기억해놓으면 좋다. 몇개 수정해서 고쳐쓸 수도 있고. 오라클은 BEGINDATA로 data가 있는 파일을 ctl과 구분지을 필요가 없는 점은 장점.
그 덕에 INFILE 뒤에 *가 붙는다.
$ sqlldr userid= sys/oracle control=/home/oracle/demo1.ctl
SQL*Loader: Release 12.2.0.1.0 - Production on 수 12월 13 16:29:26 2017
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
사용된 경로: 규약
커밋 시점에 도달 - 논리 레코드 개수 5
테이블 DEPT:
4 행이(가) 성공적으로 로드되었습니다.
로드에 대한 자세한 내용은
demo1.log
로그 파일을 확인하십시오.
SQL> select * from dept;
DEPTNO DNAME LOC
--------------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
4 행이 선택되었습니다.
오라클 로더는 column 멀티바이트도 지원하는데, STR 구문으로 레코드 구분자도 가능하다.
-demo1.ctl
LOAD DATA
INFILE '/home/oracle/demo1.dat' "STR '!!'"
INTO TABLE dept
FIELDS TERMINATED BY '@!@!'
(
deptno
,dname
,loc
,comments "replace(:comments, '\\n', chr(10))"
)
- demo1.dat(한 문장임)
10@!@!ACCOUNTING@!@!NEW YORK@!@!this is the sales\nOffice in virginia!!20@!@!RESEARCH@!@!DALLAS@!@!this is the accounting\noffice in virginia!!30@!@!SALES@!@!CHICAGO@!@!this is the consulting\noffice in virginia!!40@!@!OPERATIONS@!@!BOSTON@!@!this is the finance\noffice in virginia
$ sqlldr userid= sys/oracle control=demo1.ctl
SQL*Loader: Release 12.2.0.1.0 - Production on Wed Dec 13 18:22:00 2017
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
Path used: Conventional
Commit point reached - logical record count 3
Commit point reached - logical record count 4
Table DEPT:
4 Rows successfully loaded.
Check the log file:
demo1.log
for more information about the load.
SQL> select * from dept;
DEPTNO DNAME LOC COMMENTS
--------------- -------------- ------------- -----------------------------------
10 ACCOUNTING NEW YORK this is the sales
Office in virginia
20 RESEARCH DALLAS this is the accounting
office in virginia
30 SALES CHICAGO this is the consulting
office in virginia
40 OPERATIONS BOSTON this is the finance
office in virginia
이건 딱히 오라클 자체 지원이라기보단, ctl파일에 함수까지 지원하는 기능을 이용해서 레코드 구분자를 지어주는 역할로 보인다. 일종의 우회방법?
DBMS에 따라 LINES TERMINATE 등으로 지원하는 데도 있다.
TIBERO
이쪽 또한 전용 로더가 있다. tbloader
SQL> connect sys/tibero
Connected to Tibero.
SQL> create table dept(deptno number(2), dname varchar(13), loc varchar(15))
2 ;
Table 'DEPT' created.
SQL> commit;
Commit completed.
SQL> select * from dept;
0 row selected.
- demo1. ctl
LOAD DATA
INFILE '/home/tibero/tibero.dat'
LOGFILE '/home/tibero/tibero.log'
BADFILE '/home/tibero/tibero.bad'
APPEND
INTO TABLE dept
FIELDS TERMINATED BY ','
(
deptno
,dname
,loc
)
- tibero.dat
10,ACCOUNTING,NEW YORK
20,RESEARCH,DALLAS
30,SALES,CHICAGO
40,OPERATIONS,BOSTON
$ tbloader userid=sys/tibero control=demo1.ctl
tbLoader 5
TmaxData Corporation Copyright (c) 2008-. All rights reserved.
Start loading...
Committed and Completed successfully.
$ tbsql sys/tibero
tbSQL 5
TmaxData Corporation Copyright (c) 2008-. All rights reserved.
Connected to Tibero.
SQL> select * from dept;
DEPTNO DNAME LOC
---------- ------------- ---------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
4 rows selected.
거의 오라클하고 비슷하게 보인다.
이쪽은 아까 언급한 LINE TERMINATE가 있다.
- demo1.ctl
LOAD DATA
INFILE '/home/tibero/tibero.dat'
LOGFILE '/home/tibero/tibero.log'
BADFILE '/home/tibero/tibero.bad'
APPEND
INTO TABLE dept
FIELDS TERMINATED BY '@!@!'
LINES TERMINATED BY '!!'
(
deptno
,dname
,loc
)
- tibero.dat
10@!@!ACCOUNTING@!@!NEW YORK!!20@!@!RESEARCH@!@!DALLAS!!30@!@!SALES@!@!CHICAGO!!40@!@!OPERATIONS@!@!BOSTON
$ tbloader userid=sys/tibero control=demo1.ctl
tbLoader 5
TmaxData Corporation Copyright (c) 2008-. All rights reserved.
Start loading...
Committed and Completed successfully.
SQL> select * from dept;
DEPTNO DNAME LOC
---------- ------------- ---------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
8 rows selected.
STR에 비해 깔끔해서 좋다.
CSV는 다루기가 좋지만, 그대로 쓰는 엔드유저들이 없다 보니 어쩔 수가 없는 부분이다. 따로 파서를 변경해 줄 수 있어야 데이터를 집어넣을 수 있으니...
다음 시간엔 또 다른 걸로.