regexp_replace在单引号和空格后获取特定字符

时间:2018-11-14 08:39:43

标签: sql oracle

我在regex上不怎么好,但是我想在Info_type之后加上一个特定的单词,所以结果将是DATABASEAPPLICATIONMOBILE

示例:

Flyfast,unix.system,1-1-1,""Table X"" D-Day=""Flood"" id =123123PTIWQ Type='A' info_name=""Fast""  Info_type="""DATABASE""" Starting="10:00:10" Ending=""0000"" Comments="""NONE"""

Flyfast,unix.system,1-1-1,""Table X"" D-Day=""Flood"" id =123123PTIWQ Type='A' info_name=""Fast""  Info_type="""APPLICATION""" Starting="07:00:30" Ending=""0000"" Comments="""NONE"""

Flyfast,unix.system,1-1-1,""Table X"" D-Day=""Flood"" id =123123PTIWQ Type='A' info_name=""Fast""  Info_type="""MOBILE""" Starting="02:00:20" Ending=""0000"" Comments="""NONE"""

Flyfast,unix.system,1-1-1,""Table X"" D-Day=""Flood"" id =123123PTIWQ Type='A' info_name=""Fast""  Info_type="""DATABASE""" Starting="00:00:10" Ending=""0000"" Comments="""NONE"""

编辑:

我还有其他一些类似的数据:

Flyfast,unix.system,1-1-1,""Table X"" D-Day=""Flood"" id =123123PTIWQ Type='A' info_name=""Fast""  Info_type="""DATABASE A""" Starting="00:00:10" Ending=""0000"" Comments="""NONE"""

我尝试了SELECT REGEXP_REPLACE(name, '(.*)(Info_type\=)') FROM TAB1

1 个答案:

答案 0 :(得分:2)

这里是提取单词的方法,我认为它总是被三引号引起来

SELECT REGEXP_REPLACE(name, '^.*Info_type="""([A-Z ]*)""".*', '\1') 
FROM tab1

更新

此版本更加灵活,并允许在单词周围使用1-3引号

SELECT REGEXP_REPLACE(name, '^.*Info_type=["]{1,3}([A-Z ]*)["]{1,3}.*', '\1') 
FROM tab1

更新2 允许单词包含空格