在sql oracle中使用regexp_substr获取特定单词后的单词 [英] Get a word after specific word using regexp_substr in sql oracle

查看:62
本文介绍了在sql oracle中使用regexp_substr获取特定单词后的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过了

select regexp_substr ('sys: error: This is a message ''123:'' for column EMP_NB', '[[:alpha:]_]+',1,9) from dual

我有一列填充了这种类型的数据.

I have column filled with this type of data.

sys: error: This is a message '123:' for column EMP_NB.  
sys: error: This is a message '45346:' for column EM_NM.  
sys: error: This is a message '78324f9:' for column DEPT_NO_VL.

我需要在 Oracle SQL 中使用 regexp_substr 像下面这样的输出.挑战是字符串的长度往往会发生变化,我只需要提取字符串中 column 单词之后的字符.

I need an output like below this using regexp_substr in Oracle SQL. The challenge is the length of string tend to change and I need to extract only the characters after the column word in string.

预期产出:

EMP_NB
EM_NM
DEPT_NO_VL

推荐答案

您可以使用

select regexp_substr ('sys: error: This is a message ''123:'' for column EMP_NB', 'column[[:space:]]*([[:alpha:]_]+)', 1, 1, NULL, 1) from dual

这里,

  • column - 匹配 column
  • [[:space:]]* - 0 个或多个空白字符
  • ([[:alpha:]_]+) - 将任何一个或多个字母或下划线捕获到第 1 组中.
  • column - matches column word
  • [[:space:]]* - 0 or more whitespace chars
  • ([[:alpha:]_]+) - captures into Group 1 any one or more letters or underscores.

仅返回捕获的值,因为最后一个组 ID 参数设置为 1.

The value captured is returned only, since the last group ID argument is set to 1.

这篇关于在sql oracle中使用regexp_substr获取特定单词后的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆