Oracle SQL 子串

Oracle SQL substring

希望得到您的帮助!我正在尝试 return 从结尾开始的子字符串。和 \

这是一个示例字段

\BsadasdaCL04\files25Year\TEST20\Aug4901349013-07-25-18-96572.cca

我愿意return

5249013-07-25-18-96572

最后一个 \ 和 之间的字符数。可以变化

Oracle 版本 19.2.1.247

提前致谢!

您可以在此处将 REGEXP_SUBSTR 与捕获组一起使用:

SELECT REGEXP_SUBSTR(col, '([^\.]+)\.\S+$', 1, 1, NULL, 1)
FROM yourTable;

Demo

正则表达式的解释:

([^\.]+)  match and capture the file name (without backslash or dot)
\.        match final dot extension
\S+       followed by an extension having one or more non whitespace characters
$         end of the input

您可以使用 regexp_replace():

select regexp_replace(field, '^.*\([^.\]+)[.].*$', '')
from (select '\BsadasdaCL04\files25Year\TEST20\Aug4901349013-07-25-18-96572.cca' as field from dual) t
Select
  Regexp_substr(str, '([^\]+)\.[^.]*$',1,1,null,1) s
From( select '\BsadasdaCL04\files25Year\TEST20\Aug4901349013-07-25-18-96572.cca' str from dual);