2

please I need a query that could extract the Serial # from the Logmsg, the hard thing is that it does not follow a specific pattern, there is not fixed delimiter and the serial length is not the same always

|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 as change. serial :T5D7S18802909825, user:ahmed.o.haraz       |
|Customer Receive CPE Indoor as change. serial :T5D7S18802909830, user:ahmed.o.haraz       |
|Customer Receive CPE Indoor. serial ZTERRTHJ9303771, user:Mohamed.E176246                 |
|Customer Returned CPE. serial :21530369847SKA011094, user:ahmed.o.haraz                   |

the result will be like below:

|Serial              |
|--------------------|
|21530369847SKA011094|
|21530369847SK9078291|
|T5D7S18802909825    |
|T5D7S18802909830    |
|ZTERRTHJ9303771     |
|21530369847SKA011094|

2 Answers2

1

One method is regexp_replace(), but you have different formats for what follows serial. So:

select replace(replace(regexp_extract(logmsg, 'serial [^,]+'), 'serial ', ''), ':', '')
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
1

This is answered in https://stackoverflow.com/a/64254966/14311638

Use a combination of regexp_extract_all_sp and get_value_varchar along with the right regex pattern

Aniket Kulkarni
  • 471
  • 2
  • 2