extract serial from string that follow fuzzy pattern SQL Netezza

谁说我不能喝 提交于 2021-01-07 03:08:31

问题


please I Have a log message that contains a serial with a fuzzy pattern that hard to follow like the below

|LogMsg                                                                                    |
|------------------------------------------------------------------------------------------|
|Customer Receive CPE Indoor. serial 21530369847SKA011094, user:ahmed.o.haraz              |
|Customer Receive CPE Indoor as change. serial :21530369847SK9078291, user:Abdullah.M160275|
|Customer Receive CPE Indoor. serial:ZTERRT1H9202990                                       |
|Customer Receive CPE Indoor. serial 21530369847SKB333996 .UserName :TEDST.mohamed.badry   |
|Customer Receive CPE Indoor as change. serial :21530373727skc298302, user:Frass.m195577   |
|Customer Receive CPE Indoor. serial 21530369847SKA267112 .UserName :seller.160002         |

I need to extract the Serial from the string like the below

|Serial|
|21530369847SKA011094|
|21530369847SK9078291|
|ZTERRT1H9202990     |
|21530369847SKB333996|
|21530373727skc298302|
|21530369847SKA267112|

I got the mentioned query using regexp_replace() but it missed some of them

select replace(replace(regexp_extract(logmsg, 'serial [^,]+'), 'serial ', ''), ':', '')

回答1:


Try

select get_value_varchar(
        regexp_extract_all_sp(logmsg,
          '(serial\s*:?)([^,\s]+)'),3) as serial
from serial;

It should give you the result you are looking for

        SERIAL
----------------------
 21530369847SKA011094
 21530369847SKA267112
 21530369847SKB333996
 21530369847SK9078291
 ZTERRT1H9202990
 21530373727skc298302
(6 rows)


来源:https://stackoverflow.com/questions/64254294/extract-serial-from-string-that-follow-fuzzy-pattern-sql-netezza

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!