在oracle中使用000更新数字列值

时间:2016-11-01 11:04:02

标签: oracle

我正在尝试更新列值。列数据类型为Number。根据要求,对于正确的记录,此列将更新为000.我已将此包含在条件的其他部分,但当表格更新时,它只取0而不是000.请建议。我怎么能成为000?

MERGE INTO mem_src_extn t USING 
( 
SELECT mse.rowid row_id,
       CASE WHEN mse.type_value IS NULL OR mse."TYPE" IS NULL OR mse.VALUE_1 IS NULL or mse.VALUE_2 IS NULL THEN 100
            WHEN ( SELECT count(*) FROM cmc_mem_src cms WHERE cms.tn_id = mse.type_value ) = 0 THEN 222
            WHEN count(mse.value_1) over ( partition by type_value ) > 1 THEN 333
       ELSE 000 int_value_1 <-- here 
FROM   mem_src_extn mse
) u
ON ( t.rowid = u.row_id )
WHEN MATCHED THEN UPDATE SET t.int_value_1 = u.int_value_1

After Update :

1 个答案:

答案 0 :(得分:-1)

如果您的列int_value_1是varchar2,请使用quote

MERGE INTO mem_src_extn t USING 
( 
SELECT mse.rowid row_id,
       CASE WHEN mse.type_value IS NULL OR mse."TYPE" IS NULL OR mse.VALUE_1 IS NULL or mse.VALUE_2 IS NULL THEN '100'
            WHEN ( SELECT count(*) FROM cmc_mem_src cms WHERE cms.tn_id = mse.type_value ) = 0 THEN '222'
            WHEN count(mse.value_1) over ( partition by type_value ) > 1 THEN 
'333'
       ELSE '000' int_value_1 
       END
FROM   mem_src_extn mse
) u
ON ( t.rowid = u.row_id )
WHEN MATCHED THEN UPDATE SET t.int_value_1 = u.int_value_1

但如果您有一个数字,并希望只看到000 0 {} 您可以将to_char与格式字符串

一起使用
select to_char(int_value_1,'099') from mem_src_extn;