【发布时间】:2020-03-28 03:00:19
【问题描述】:
假设我有
“你好,这是 11,我想要 0032,但有 013 和 5”
“您好,这是 0011,我想要 0032,但有 0013 和 0005”
已编辑
【问题讨论】:
-
你不能拥有它的“任何”长度。替换会导致溢出。
-
如果我最多需要 4 个这样的句子呢?
标签: oracle regexp-replace
假设我有
“你好,这是 11,我想要 0032,但有 013 和 5”
“您好,这是 0011,我想要 0032,但有 0013 和 0005”
已编辑
【问题讨论】:
标签: oracle regexp-replace
我怀疑单个REGEXP_REPLACE 是否足以完成您的任务,但您可以分两步完成:
代码如下:
SELECT
REGEXP_REPLACE(
REGEXP_REPLACE('Hello this is 11 and i want 0032 but there is 013 and 5'
,'(\d+)','000\1') -- Add three 0-digits to any number
,'0+(\d{4})','\1') -- Remove all 0-digits prior to the last 4 digits of any number
FROM dual
结果:
您好,这是 0011,我想要 0032,但有 0013 和 0005
【讨论】: