Preface : Today in the MySQL query encountered a problem, the situation is this, if now I have a table inside a field SCODE (indicating the product number), then there is a string stored multiple product number, such as "0001ME,0002BL" is a string, If it is called STR, it is intended to use in the way, that is, want to put Str as the condition, where scode in "0001ME,0002BL", but did not succeed, and then read the MySQL document, find various functions, and finally found the InStr function, Problem solved, let's talk about the result process
1. At the beginning, the string str has been converted to a similar in parameter, 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);
summary : Looks very small one method, if does not know the method time is very painful ah.
Summary: MySQL uses strings as a query condition