0

你能帮我解析字符串中的数字吗?

我想从字符串中选择第一次和第二次出现的数字,如下所示:

 PKGGeneral.SetObjectAttribute(i_DimObject=4,i_ObjectID=163225122,i_Attribute=NAME,i_Value (VarChar2)=xDSL:1.4.51);

或者

PKGPort.CreateLogicalPort(io_portid=197604073,i_name=VLAN_segment:7239554:IPTV GPON_Port_A,i_nodeid=123431890,i_porttypeid=1900000150,i_bandwidthid=1,i_parentportid=186300246);

第一次出现设置在 A 列中,第二次出现设置在 B 列中。

结果: 示例 A

column A : 4
column B : 163225122

示例 B

column A : 197604073
column B : 7239554

谢谢你。

4

1 回答 1

-1

使用regexp_substr()

select
    regexp_substr(mycol, '\d+', 1, 1) colA,
    regexp_substr(mycol, '\d+', 1, 2) colB
from mytable

\d+捕获一系列连续的数字。第四个参数指示应该返回哪个事件。

DB Fiddle 上的演示

with mytable as (
    select 'PKGGeneral.SetObjectAttribute(i_DimObject=4,i_ObjectID=163225122,i_Attribute=NAME,i_Value (VarChar2)=xDSL:1.4.51);' mycol from dual
    union all
    select 'PKGPort.CreateLogicalPort(io_portid=197604073,i_name=VLAN_segment:7239554:IPTV GPON_Port_A,i_nodeid=123431890,i_porttypeid=1900000150,i_bandwidthid=1,i_parentportid=186300246);' from dual
)
select
    regexp_substr(mycol, '\d+', 1, 1) colA,
    regexp_substr(mycol, '\d+', 1, 2) colB
from mytable
可乐 | COLB     
:-------- | :--------
4 | 163225122
197604073 | 7239554  
于 2020-01-30T23:00:27.143 回答