REGEXP_SUBSTR-Oracle

REGEXP_SUBSTR-Oracle

如何使用 REGEXP_SUBSTR 从下面获取第 4 个正斜杠后的所有单词?(使用 oracle sql)

/plt/v1/v2/shipment-mgr/grids/shipoppre

我只需要

shipment-mgr/grids/shipoppre

谢谢

假设列名是 col1:

select substr(col1, instr(col1, '/', 1, 4) + 1)
from ...

你不需要正则表达式;只要你可以使用标准的 substr 和 instr,它就更好了,因为 regexp 比较慢。

使用REGEXP_REPLACE

REGEXP_REPLACE( your_column, '^(/.*?){3}/' )

使用REGEXP_SUBSTR

REGEXP_SUBSTR( your_column, '^(/.*?){3}/(.*)$', 1, 1, NULL, 2 )

或使用 INSTRSUBSTR:

SUBSTR( your_column, INSTR( your_column, '/', 1, 4 ) + 1 )