mysql instr () function

1) instr () function format (commonly known as: character lookup function)

Formats: instr (string1, string2) / instr (the source string, the target string)

Two formats: instr (string1, string2 [, start_position [, nth_appearance]]) / instr (the source string, the target string, the starting position, matching serial number)

Analysis: To find the value of string2 in string1, from the values ​​given start_position: starting a search (i.e., position) in string1, first search nth_appearance (s) of occurrence string2.

NOTE: In the Oracle / PLSQL in, instr function returns the position of the character string to be taken in the source string. Retrieved only once , that is to say from the beginning of the end character to character ends.

2) Examples

Formats

1 select instr ( 'helloworld', 'l') from dual; - Returns: 3 Default first time "l" position 
2 select instr ( 'helloworld', 'lo') from dual; - return result : 4 namely: the "lo", the position "l" began to appear 
3 select instr ( 'helloworld', 'wo') from dual; - returns: i.e. position 6 "w" began to appear

 

Format two

1 select instr ( 'helloworld', 'l', 2,2) from dual; - returns the result: that is to say 4: In the "HelloWorld" section 2 (e) numbers starting position, to find the second occurrence of " l "position 
2 select instr ( 'helloworld', 'l', 3,2) from dual; - returns the result: that is to say 4: in the" helloworld "section 3 (l) numbers starting position, a second lookup "l" occurrences of position 
3 select instr ( 'helloworld', 'l', 4,2) from dual; - returns: 9 that is: the beginning of "helloworld" section 4 (l) position No. Find "l" position of the second occurrence of the 
4 select instr ( 'helloworld', 'l', - 1,2) from dual; - returns the result: that is to say 4: countdown "helloworld" first (d) resolution starting position, by looking back "l" position of the second occurrence of the 
5 select instr ( 'helloworld', 'l', - 2,2) from dual; - returns: 4 and fourth Like 
6 select instr ( 'helloworld', 'l', 2,3) from dual; - returns the result: that is to say 9: in the "helloworld" in section 2 (e) numbers starting position, look for the third occurrence "l" position 
7 select instr ( 'helloworld','L', - 2,3) from dual; - return: that is to say 3: Start the countdown "helloworld" section 2 (l) number position, look back "l" appears in the third position

 

NOTE: InStr oracle MySQL fuzzy query and the like in the () function has the same query results; as follows:

* from tableName WHERE A SELECT name like '%% HelloWorld'; 
SELECT * from tableName WHERE A InStr (name, 'HelloWorld')> 0; - effect of these two statements is the same

Guess you like

Origin www.cnblogs.com/wang-yaz/p/11460711.html