2016-12-30 87 views
1

我想替換將被加載到DOMAIN_LABEL列如下的值:如何用sql loader中的另一個值替換值?

如果3 cntg03與cntg03

更換如果2 cntg02與cntg02

更換如果1 cntg01與cntg01

替換

這可能嗎?

我有以下控制文件:

LOAD DATA 
INFILE u/local/r2x/data/rda_prod_cntg.dat 
TRUNCATE 
INTO TABLE R2X1.RDA_PROD_CNTG 
FIELDS TERMINATED BY ',' 
OPTIONALLY ENCLOSED BY '\"' 
(
ITEM, 
GLOBAL_DOMAIN_TYPE CONSTANT 'S', 
GLOBAL_ID CONSTANT 10, 
GLOBAL_DOMAIN_DESC CONSTANT 'Sales Forecast', 
filler2 FILLER, 
filler3 FILLER, 
filler4 FILLER, 
filler5 FILLER, 
filler6 FILLER, 
filler7 FILLER, 
filler8 FILLER, 
filler9 FILLER, 
filler10 FILLER, 
filler11 FILLER, 
filler12 FILLER, 
filler13 FILLER, 
filler14 FILLER, 
filler15 FILLER, 
filler16 FILLER, 
filler17 FILLER, 
filler18 FILLER, 
filler19 FILLER, 
filler20 FILLER, 
DOMAIN_ID, 
DOMAIN_LABEL, 
filler23 FILLER, 
filler24 FILLER, 
filler25 FILLER, 
filler26 FILLER 
) 

回答

1

可以使用case表達式該列。

DOMAIN_LABEL "case when :DOMAIN_LABEL = '3 cntg03' then 'cntg03' 
        when :DOMAIN_LABEL = '2 cntg02' then 'cntg02' 
        when :DOMAIN_LABEL = '1 cntg01' then 'cntg01' 
       end" 

如果這已爲多個值來完成,如果該模式是相似的,你可以使用substr功能,讓所有的字符從第三個字符開始,

DOMAIN_LABEL "substr(:DOMAIN_LABEL,3)" 

完整的腳本將是

LOAD DATA 
INFILE u/local/r2x/data/rda_prod_cntg.dat 
TRUNCATE 
INTO TABLE R2X1.RDA_PROD_CNTG 
FIELDS TERMINATED BY ',' 
OPTIONALLY ENCLOSED BY '\"' 
(
ITEM, 
GLOBAL_DOMAIN_TYPE CONSTANT 'S', 
GLOBAL_ID CONSTANT 10, 
GLOBAL_DOMAIN_DESC CONSTANT 'Sales Forecast', 
filler2 FILLER, 
filler3 FILLER, 
filler4 FILLER, 
filler5 FILLER, 
filler6 FILLER, 
filler7 FILLER, 
filler8 FILLER, 
filler9 FILLER, 
filler10 FILLER, 
filler11 FILLER, 
filler12 FILLER, 
filler13 FILLER, 
filler14 FILLER, 
filler15 FILLER, 
filler16 FILLER, 
filler17 FILLER, 
filler18 FILLER, 
filler19 FILLER, 
filler20 FILLER, 
DOMAIN_ID, 
DOMAIN_LABEL "substr(:DOMAIN_LABEL,3)", 
/* or you can use a case expression 
DOMAIN_LABEL "case when :DOMAIN_LABEL = '3 cntg03' then 'cntg03' 
        when :DOMAIN_LABEL = '2 cntg02' then 'cntg02' 
        when :DOMAIN_LABEL = '1 cntg01' then 'cntg01' 
       end", 
*/ 

filler23 FILLER, 
filler24 FILLER, 
filler25 FILLER, 
filler26 FILLER 
) 
+0

試了兩個並得到一個類似的錯誤:期待「,」或「)」,發現「案件」。 DOMAIN_LABEL的情況下:DOMAIN_LABEL = 3 cntg03然後cntg03 >>/u/loc – Adil

+0

請參閱編輯..我發佈了此附加的完整腳本。對不起,函數必須是'substr'而不是'substring'。 –

+0

謝謝,都有效。這是一個額外的報價留下的是這個問題。 – Adil

相關問題