FIELD (S,s1,s2,...) With the Find_in_set (S,S1) function------"These 2 functions all return the position where the specified string appears in the source string (all the first occurrence), but the parameters of the 2 function are different, the former is a list-like parameter, the latter is a whole string of parameters. (The top s are the specified string, the former S1 and S2 are the list of strings, the latter S1 as a whole string)
FIELD (S,s1,s2,...):
function that returns the position of the specified string field (S,s1,s2,...)
FIELD (S,s1,s2,...) Return string s in List S1,s2, ... The first occurrence of the position, in the case where S is not found, the return value is 0.
If S is null, the return value is 0, because null cannot be compared equally with any value.
SELECT FIELD (‘Hi‘,‘Hihi‘,‘Hey‘,‘Hi‘,‘Bas‘)AsColl,field (‘Hi‘,‘Hihi‘,‘Lo‘,‘Hilo','foo') as col2
FIELD (' Hi ', ' hihi ', ' Hey ', ' Hi ', ' bas ') function in the string hi appears in the 3rd string position of the list, so the return result is 3
FIELD (' Hi ', ' hihi ', ' lo ', ' Hilo ', ' foo ') list does not have a string hi, so the return result is 0
Find_in_set (S1,S2):
function Find_in_set (S1,S2) to return substring position
Find_in_set (S1,S2) returns the position of the string S1 in the string list s2, where the list of strings is one by multiple commas
', ' a list of separate strings. If S1 is not S2 or S2 is an empty string, the return value is 0. If either parameter is NULL, the return value is null.
This function will not work correctly when the first parameter contains a comma ', '.
SELECT Find_in_set ('hi','hihi,hey,hi,bas')
Although Find_in_set (S1,S2) and field (S,s1,s2,...) Two function formats are different, but similar, can return the position of the specified string in the list of strings
function that returns the position of the specified string field (S,s1,s2,...) and Find_in_set (S1,S2) function