Oracle 正则表达式在特殊字符后显示字符串

Oracle Regular Expression to show string a string after a special character

我正在使用正则表达式来获取特殊字符“:”出现后的所有子字符串-

给定的字符串-

Reason for creating the box: Order done by me (100005 - Error Format: Value ABC000001606 of EmpId is not valid)

预期输出-

Order done by me (100005 - Error Format: Value ABC000001606 of EmpId is not valid)

我尝试了这个,但没有按要求工作-

SELECT REGEXP_SUBSTR('Reason for creating the box: Order done by me (100005 - Error Format: Value ABC000001606 of EmpId is not valid)', ':[^ ])') "REGEXPR_SUBSTR" FROM DUAL;

你能帮忙吗?

这里有两种方法。

这个使用了 REGEXP_SUBSTR,正如你所要求的。

with c as (select 'Reason for creating the box: Order done by me (100005 - Error Format: Value ABC000001606 of EmpId is not valid)' str from dual)
SELECT substr(REGEXP_SUBSTR(c.str, ':[^)]+'),2) "REGEXPR_SUBSTR" FROM c;

这个使用substr+instr+length,如果你有一个大数据集,它有更好的性能。

with c as (select 'Reason for creating the box: Order done by me (100005 - Error Format: Value ABC000001606 of EmpId is not valid)' str from dual)
select substr(c.str, instr(c.str, ':')+1, length(c.str)-1)
from c;

这两个都有一个 WITH 子句,使示例查询更具可读性。