从字符串中提取单词之后的单词

时间:2020-03-17 11:56:56

标签: sql oracle

我有一个大注释栏,其中有一个单词NUMBER_OF_SERVERS_03,03可以是任意2位数字,也可以是n位数字,之后是数字,例如NUMBER_OF_SERVERS_03 2我想在此之后提取数字,例如< / p>

Notes Column - 'asdasd asdasda asdasd NUMBER_OF_SERVERS_03 24 hkashii rwnijt'
output will should be 24

谢谢 拉克什

2 个答案:

答案 0 :(得分:1)

您需要将REGEXP_SUBSTR匹配参数一起使用,如下所示:

SQL> SELECT
  2      REGEXP_SUBSTR('asdasd asdasda asdasd NUMBER_OF_SERVERS_03 24 hkashii rwnijt',
  3      'NUMBER_OF_SERVERS_[0-9]+\s+([0-9]+)', 1, 1, NULL, 1) as RESULT
  4  FROM
  5      DUAL;

RE
--
24

-- Example with spaces and different server number
SQL> SELECT
  2      REGEXP_SUBSTR('asdasd asdasda asdasd NUMBER_OF_SERVERS_11   10 hkashii rwnijt',
  3      'NUMBER_OF_SERVERS_[0-9]+\s+([0-9]+)', 1, 1, NULL, 1) as RESULT
  4  FROM
  5      DUAL;

RE
--
10

SQL>

干杯!

答案 1 :(得分:0)

您可以使用regexp_replace()

select regexp_replace(notes, '^.*NUMBER_OF_SERVERS_[0-9]+[^0-9]*([0-9]+).*$', '\1')
from (select 'asdasd asdasda asdasd NUMBER_OF_SERVERS_03 24 hkashii rwnijt' as notes from dual)

如果您知道数字在该字符串后跟一个空格,则可以将其简化为:

select regexp_replace(notes, '^.*NUMBER_OF_SERVERS_[0-9]+ ([0-9]+).*$', '\1')