从oracle中的字符串中提取值
Extract value from a string in oracle
我需要从字符串中提取特定的值。
示例:1571-P003 031-OHD-SSKS-SSMO
输出:P003 031
这是一个选项,returns 来自该字符串的第 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>
或者,另一个,第一个和第二个 -
符号之间的 returns 子串:
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>
我需要从字符串中提取特定的值。
示例:1571-P003 031-OHD-SSKS-SSMO
输出:P003 031
这是一个选项,returns 来自该字符串的第 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>
或者,另一个,第一个和第二个 -
符号之间的 returns 子串:
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>