Alex
Alex

Reputation: 1124

Oracle PL/SQL: Split string and get last delimited substring

I am looking for a way to split a string in Oracle PL/SQL and get the last substring separated by the delimiter.

Basically, I have a file-path /dir1/dir2/dir3/file.txt and I want to get a filename.

Most of solutions I find are too long and are basically two step process: split and get the last.

Is there a short way to do this in one step

Upvotes: 1

Views: 8340

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1271161

You can use regexp_substr():

select regexp_substr(filepath, '[^/]+$', 1, 1)

This will take all characters after the final delimiter.

Upvotes: 4

Related Questions