【发布时间】:2020-02-09 04:35:08
【问题描述】:
我试图仅从字符串返回匹配项,如果另一个模式首先在 Oracle 中使用 RegEx_Like 和 RegExp_Substr 匹配,但我得到的结果好坏参半。
以下是我拥有的数据示例以及我试图从中返回的数据:
+------------------+----------+ |数据 |目标 | +------------------+----------+ | 201301-P706466 肯尼迪经典 | P706466 | | 201301-706466 世界资源研究所经典 | 706466 | | 201301 706466 肯尼迪经典 | 706466 | | 201301 P706466 WRI 经典 | 706466 | | 201910-MLB-CVG4 |空 | | 201209-肯尼迪经典 |空 | | 201203-WRI 经典 |空 | | 201209 肯尼迪经典 |空 | | 201203 世界资源研究所经典 |空 | +------------------+----------+查询:
select pid.location
, pnm.pn as mpn
, pid.pn as pn
, pid.batch
, pid.goods_rcvd_batch as grb
, pid.sn
, pid.bin
, Case When RegExp_Like(pid.bin, ''''^\d{6}\-|^\d{6}\s'''') Then RegExp_Substr(pid.bin, ''''\d{6}|(P)\d{6}.*?(\d{6})|((P)\d{6})'''')
End As Bin_Esn
from pn_inventory_detail pid
join pn_interchangeable pni on pid.pn = pni.pn_interchangeable
join pn_master pnm on pni.pn = pnm.pn
where pid.installed_ac is null
and pid.owner is null
and pid.loan_category is null
and pid.nha_pn is null
我尝试了 this 的不同变体,但在 regex101 上,但正如您在导航到链接后所看到的那样,它比我需要的匹配更多。
我想我可能会一起走错路,这就是我在这里的原因。话虽如此,哪种模式适用于我的情况,并且最有效?
【问题讨论】: