如何在 sql 加载程序中用另一个值替换一个值?
How do I replace a value with another value in sql loader?
我想替换将加载到 domain_label 列的值,如下所示:
if 3 cntg03 替换为 cntg03
if 2 cntg02 替换为 cntg02
if 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
)
您可以对该列使用 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
函数并获取从第 3 个字符开始的所有字符,
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
)
我想替换将加载到 domain_label 列的值,如下所示:
if 3 cntg03 替换为 cntg03
if 2 cntg02 替换为 cntg02
if 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
)
您可以对该列使用 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
函数并获取从第 3 个字符开始的所有字符,
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
)