从oracle中的字符串中提取值

问题描述 投票:-1回答:1

我需要从字符串中提取某些值。

示例:1571-P003 031-OHD-SSKS-SSMO

输出:P003 031

oracle substr
1个回答
0
投票

这是一个选项,它返回该字符串中的第2个和第3个单词:

SQL> with test (col) as
  2    (select '1571-P003 031-OHD-SSKS-SSMO' from dual)
  3  select regexp_substr(col, '\w+', 1, 2) ||' ' ||
  4         regexp_substr(col, '\w+', 1, 3) result
  5  from test;

RESULT
--------
P003 031

SQL>

或者,另一个,返回第1和第2个-标志之间的子串:

SQL> with test (col) as
  2    (select '1571-P003 031-OHD-SSKS-SSMO' from dual)
  3  select substr(col, instr(col, '-', 1, 1) + 1,
  4                     instr(col, '-', 1, 2) - instr(col, '-', 1, 1) - 1
  5               ) result
  6  from test;

RESULT
--------
P003 031

SQL>
© www.soinside.com 2019 - 2024. All rights reserved.