1

可以在 sql loader 中使用 IF CLAUSE 吗?我写了一个代码,但它给了我错误。

INTO TABLE TF_RTB9_DTL 
WHEN ((01) = 'D') OR (if 
(POA_COU_VAL = 0) 
then MAST_POA_ID = null 
end if) 
FIELDS TERMINATED BY "~" OPTIONALLY ENCLOSED BY '"' 
TRAILING NULLCOLS 
( 

TRANS_TYP POSITION(3), 
BO_ID , 
NAME , 
MID_NAM , 
LAS_NAM , 
PAN , 
NAM_FIR_JOINT , 
MIDD_NAM_FIR_JOINT, 
LAS_NAM_FIR_JOINT , 
PAN_FIR_JOINT , 
NAM_SEC_JOINT , 
MIDD_NAM_SEC_JOINT, 
LAS_NAM_SEC_JOINT , 
PAN_SEC_JOINT , 
ADD_LIN_1 , 
ADD_LIN_2 , 
ADD_LIN_3, 
CITY , 
STATE , 
COUNTRY , 
PIN_COD , 
PERM_ADD_LIN_1 , 
PERM_ADD_LIN_2 , 
PERM_ADD_LIN_3 , 
PERM_CITY , 
PERM_STATE , 
PERM_COUNTRY , 
PERM_PIN_COD , 
POA_COU_VAL , 
MAST_POA_ID , 
TRANS_ID 
)

如果 POA_COU_VAL 为 0,则 POA_COU_VAL 必须为空,并且应在 TRANS_ID 中输入下一个值。我怎样才能做到这一点?

4

2 回答 2

4

SQL*Loader is a program for loading large batches of data. It has only limited facilities for manipulating the data during the load process.

If you want to transform the data you should be using external tables instead. These are very similar to SQL*Loader (the definition uses virtually the same syntax but they present the data file to the database as a table. That means you can use SQL on it. So instead on invoking SQL*Loader from the command line you woudl run an insert statement like this:

insert into target_table
select * from external table;

Only in your situation you need to explode the project of the SELECT clause so you can include a CASE() statement to implement your additional logic.

Find out more about external tables here.

于 2012-08-02T07:46:55.683 回答
1

SQL*Loader WHEN clause has only limited boolean operators, especially OR is missing ( see http://docs.oracle.com/cd/B19306_01/server.102/b14215/ldr_control_file.htm#i1005657).

If you have to use SQL*Loader (and can't switch to external tables as APC suggested), you need to multiply the INTO sections for each part of your OR clause.

For example:

INTO TABLE TF_RTB9_DTL 
WHEN (01) = 'D'
FIELDS TERMINATED BY "~" OPTIONALLY ENCLOSED BY '"' 
TRAILING NULLCOLS 
( 
TRANS_TYP POSITION(3),
...      
...      
MAST_POA_ID
)
INTO TABLE TF_RTB9_DTL 
WHEN POA_COU_VAL = '0'
FIELDS TERMINATED BY "~" OPTIONALLY ENCLOSED BY '"' 
TRAILING NULLCOLS 
( 
TRANS_TYP POSITION(3),
...      
...      
MAST_POA_ID "NULL"
)

Or consider using the NULLIF function ( http://docs.oracle.com/cd/B19306_01/server.102/b14215/ldr_field_list.htm#i1009345 )

...
MAST_POA_ID NULLIF POA_COU_VAL = '0'
...

SQL*Loader is a a tricky tool, you'd most probably get quicker results with external tables, if you are able to use them (file has to be on the Oracle Server machine whereas SQL*Loader is able connect to any Oracle instance).

于 2012-08-03T14:01:48.057 回答