OraclE
음수 부호가 뒤에 있을 경우 LOADER로 숫자 DATA를 올리는 방법
타마마임팩트_쫀
2010. 5. 25. 18:21
===========================================================
음수 부호가 뒤에 있을 경우 LOADER로 숫자 DATA를 올리는 방법
===========================================================
음수 부호가 뒤에 있을 경우 LOADER로 숫자 DATA를 올리는 방법
===========================================================
PURPOSE
---------
음수 부호가 뒤에 있을 경우 LOADER로 숫자 DATA를 올리는 방법에
대해 알아보도록 한다.
Explanation
-----------
간혹 SQL*LOADER를 사용하는 사람들 중에 data file 내의
숫자 field의 부호가 뒤에 붙어 있거나 특정한 값을 읽어
그 값이 무엇인가에 따라 숫자를 음수와 양수로 만들어야
하는 경우가 있다. 이경우에는 SQL*LOADER의 기능으로는
해결방법이 없으나 다음과 같이 SQL 함수를 사용해서 해결
이 가능하다.
만약 다음과 같은 table이 있다고 가정한다.
create table test_table
(a number(3), b number(3));
그리고 data가 있는 test.dat는 다음과 같다고 가정한다.
create table test_table
(a number(3), b number(3));
그리고 data가 있는 test.dat는 다음과 같다고 가정한다.
============
100-,3
222,1
============
100-,3
222,1
============
그렇다면 control file을 다음과 같이 작성하여 loader를
동작시키면 원하는 결과를 얻을수 있다.
동작시키면 원하는 결과를 얻을수 있다.
test.ctl
============
load data
infile 'test.dat'
replace
into table test_table
fields terminated by ","
trailing nullcols
(a integer external "decode(substr(:a,-1),'-',rtrim(:a,'-')*-1,:a)",
b integer external)
======================
============
load data
infile 'test.dat'
replace
into table test_table
fields terminated by ","
trailing nullcols
(a integer external "decode(substr(:a,-1),'-',rtrim(:a,'-')*-1,:a)",
b integer external)
======================
이때 sqlplus 에서 확인을 하면 결과는 다음과 같다.
SQL> select * from test_table;
A B
------ -----
-100 3
222 1
A B
------ -----
-100 3
222 1