Original: http://blog.csdn.net/qing_gee/article/details/41646503
When your query condition is a string variable, what do you do, such as the string may be "0001ME,0002BL" or "0001ME", then how to get the desired result according to the condition, I will tell you the InStr method of the great.
1. At the beginning, the string str is converted to the parameters of the in function, as follows
SELECT * from Stocks_orderlist s where S.scode in ("0001ME", "0002BL") LIMIT 10; Select CONVERT (CONCAT ("\ '", REPLACE ("0001ME,0002BL", "\,", "\ ' \,\ '"), "\"), CHAR); SELECT * from Stocks_orderlist s where S.scode in (CONVERT (CONCAT ("\" ", REPLACE (" 0001ME,0002BL "," \, "," \ "\,\" ")," \ ""), CHAR)) LIMIT 10;
Though I turned Str into what I wanted, I later thought that in the parameter is a list set, I promptly converted Str into the so-called in Parameter form, but certainly is a string, so busy for a long time, a little want to give up the feeling, but think back, must have not found the right way , so I found the InStr function.
2.instr function, look at the help document means to find out substr first problem in Str, try the following
Select INSTR ("0001ME,0002BL", "0003ME"); Select INSTR ("0001ME,0002BL", "0001ME"); Select INSTR ("0001ME,0002BL", "0002BL"); SELECT * from Stocks_orderlist s where INSTR ("0001ME,0002BL", S.scode);
String variables for MySQL query criteria