从字符串 SQL 中提取序列号 Netezza
extract serial from string SQL Netezza
我需要一个可以从 Logmsg 中提取序列号的查询,困难的是它不遵循特定的模式,没有固定的分隔符并且序列长度总是不一样
|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 |
结果如下:
|Serial |
|--------------------|
|21530369847SKA011094|
|21530369847SK9078291|
|T5D7S18802909825 |
|T5D7S18802909830 |
|ZTERRTHJ9303771 |
|21530369847SKA011094|
一种方法是regexp_replace()
,但是serial
后面的内容有不同的格式。所以:
select replace(replace(regexp_extract(logmsg, 'serial [^,]+'), 'serial ', ''), ':', '')
这在
中得到了回答
结合使用 regexp_extract_all_sp
和 get_value_varchar
以及正确的正则表达式模式
我需要一个可以从 Logmsg 中提取序列号的查询,困难的是它不遵循特定的模式,没有固定的分隔符并且序列长度总是不一样
|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 |
结果如下:
|Serial |
|--------------------|
|21530369847SKA011094|
|21530369847SK9078291|
|T5D7S18802909825 |
|T5D7S18802909830 |
|ZTERRTHJ9303771 |
|21530369847SKA011094|
一种方法是regexp_replace()
,但是serial
后面的内容有不同的格式。所以:
select replace(replace(regexp_extract(logmsg, 'serial [^,]+'), 'serial ', ''), ':', '')
这在
结合使用 regexp_extract_all_sp
和 get_value_varchar
以及正确的正则表达式模式