mysqlfind-in-set

What's wrong with my sql when I using FIND_IN_SET function?


In my table called testtb has a column that storing file path,Now I want to find the filed which start in C:\.I use the sql,but it always return 0.what's wrong?

--example 
select  FIND_IN_SET('C:\\', 'C:\\abc.png' )
-- my sql
 select  FIND_IN_SET('C:\\', filepath) from testtb;

Here is my table data:

id,    filepath,               srcfilepath
'1', 'C:\20160101\abc.jpg', 'C:\20160101\abc.jpg'
'2', 'D:\20160101\abc.jpg', 'D:\20160101\abc.jpg'
'3', 'E:\TP\20160101\abc.jpg', 'E:\TP\20160101\abc.jpg'

Solution

  • You are just confused. find_in_set() refers to sets of values in MySQL. In MySQL, these are values separated by commas: '1,2,3' or 'abc,def,ghi'.

    I think you are looking for the instr() or position() function:

    select instr('C:\\abc.png', 'C:\\')