[linux] basename() function for Mysql

Andrew Morgan morgan at orst.edu
Fri Oct 2 18:41:00 PDT 2009


On Fri, 2 Oct 2009, Reitsma, Rene - COB wrote:

> Dear All,
>
> I need to extract the filename from a file path in MySQL.
>
> On the linux command line I use 'basename'
>
>> basename /foo/goo/zoo
>
> zoo
>
> In MySQL  I'd love to use something like: select basename(complete_path)
> from ...
>
> But unfortunately, I have not found anything like that yet.
>
> Can you help?

Have a look at the substring_index() function:

   http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_substring-index

Something like:

   substring_index('/foo/goo/zoo', '/', -1)

should work.

 	Andy


More information about the linux mailing list