正则表达式解析112 ^ 3 ^ 1 ^ 1 ^ [重复]

问题描述 投票:-1回答:1

我需要将像112^3^1^1^这样的字符串解析为单独的值。

第一个('112')是order_no,第二个是line_no,第三个是release_no,第四个是receipt_no。

我可以在Oracle中使用什么样的正则表达式?

sql regex oracle
1个回答
2
投票
with demo (str) as
     ( select '112^3^1^1^' from dual )
select str
     , regexp_substr(str,'[^^]+',1,1) as order_no
     , regexp_substr(str,'[^^]+',1,2) as line_no
     , regexp_substr(str,'[^^]+',1,3) as release_no
     , regexp_substr(str,'[^^]+',1,4) as receipt_no
from   demo;

STR        ORDER_NO   LINE_NO   RELEASE_NO   RECEIPT_NO
---------- ---------- --------- ------------ ----------
112^3^1^1^ 112        3         1            1

这取决于具有值的每个组件,因为它使用的模式是“一个或多个不是^的字符”。如果缺少值,则需要进行一些调整,例如'112^3^^1^'(没有release_no)。

© www.soinside.com 2019 - 2024. All rights reserved.