function that returns the position of the specified string field (S,s1,s2,...) and Find_in_set (S1,S2) function

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.