Skip to content
Advertisement

How to get file extension of file as a result of sql query?

I have a table named datas and I’m executing a query like this:

It returns results like this:

In the Type column I am geting name of the file. I need to get the file extension of the file name in the Type column. How can I achieve this?

Examples:

Advertisement

Answer

You can use SUBSTRING_INDEX. Like this:

EDIT

If you see the docs on this function I think this will apply well to you requirements.

Returns the substring from string str before count occurrences of the delimiter delim. If count is positive, everything to the left of the final delimiter (counting from the left) is returned. If count is negative, everything to the right of the final delimiter (counting from the right) is returned. SUBSTRING_INDEX() performs a case-sensitive match when searching for delim.

This will also handle a case like this:

EDIT2

If you are using oracle. Please tag the question in the correct matter next time. There is no SUBSTRING_INDEX in oracle. But what I can see you can do this quite easy:

Full query like this:

Reference here

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement