Update table records - Add '00' for each 2 Numbers

时间:2017-06-14 10:27:59

标签: sql oracle

I have a table with many millions of records, in oracle. And in this table there's a field that needs to be updated. I need to add a '00' for each to numbers. Like this:

1234 -> 120034

123456 -> 1200340056

The length of this field can vary between 2 and 16 numbers. Because of this variation in length, I have no ideia how to make this update. Can same one give a hand please?

Thank you.

1 个答案:

答案 0 :(得分:3)

您可以使用以下内容:

UPDATE your_table
SET your_value = REGEXP_REPLACE(
                   REGEXP_REPLACE(
                     your_value,
                     '(\d\d)',
                     '\100'
                   ),
                  '^((\d\d00)*\d\d)00$',
                  '\1'
                );