当前位置:网站首页>Explanation and application of instr() function in Oracle

Explanation and application of instr() function in Oracle

2022-06-28 07:44:00 Zeiyalo

from : Click here to see the author

1)instr() Format of function ( Be commonly called : Character lookup function )
INSTR( string, substring [, start_position [, th_appearance ] ] )

Parameters :
string - String to search . The string can be CHAR,VARCHAR2,NCHAR,NVARCHAR2,CLOB or NCLOB Other types .
substring - In the string (string) Substring searched in . The substring can be CHAR,VARCHAR2,NCHAR,NVARCHAR2,CLOB or NCLOB Other types .
start_position - Optional . Position in the string where the search will begin . If omitted , The default is 1. The first position in the string is 1. If start_position It's a negative number ,INSTR The function evaluates from the end of the string start_position Number of characters , Then search the beginning of the string .
nth_appearance - Optional . The second part of the substring n One appears . If omitted , The default is 1.
Return value

Returns a numeric value . The first position in the string is 1. If not found in the string substring, that INSTR Function will return 0.

Format 1 :instr( string1, string2 ) / instr( The source string , Target string )

Format two :instr( string1, string2 [, start_position [, nth_appearance ] ] ) / instr( The source string , Target string , The starting position , Match serial number )

analysis :string2 The value of should be in string1 Search for , It's from start_position The values given ( namely : Location ) Start in string1 retrieval , Search page nth_appearance( A few ) time string2.

notes : stay Oracle/PLSQL in ,instr Function returns the position of the string to be intercepted in the source string . Search only once , That is to say, from the beginning of a character to the end of a character .

example :

1. Format 1:

1 select instr('helloworld','l') from dual; -- Return results :3     By default, it appears for the first time “l” The location of 
2 select instr('helloworld','lo') from dual; -- Return results :4     namely : stay “lo” in ,“l” Where it started to appear 
3 select instr('helloworld','wo') from dual; -- Return results :6     namely “w” Where it started to appear 

2. Format 2:

1 select instr('helloworld','l',2,2) from dual;  -- Return results :4     in other words : stay "helloworld" Of the 2(e) No. 1 position starts , Look for the second time “l” The location of 
2 select instr('helloworld','l',3,2) from dual;  -- Return results :4     in other words : stay "helloworld" Of the 3(l) No. 1 position starts , Look for the second time “l” The location of 
3 select instr('helloworld','l',4,2) from dual;  -- Return results :9     in other words : stay "helloworld" Of the 4(l) No. 1 position starts , Look for the second time “l” The location of 
4 select instr('helloworld','l',-1,1) from dual;  -- Return results :9     in other words : stay "helloworld" The last of 1(d) No. 1 position starts , Go back and look for the first time “l” The location of 
5 select instr('helloworld','l',-2,2) from dual;  -- Return results :4     in other words : stay "helloworld" The last of 1(d) No. 1 position starts , Look back for the second time “l” The location of 
6 select instr('helloworld','l',2,3) from dual;  -- Return results :9     in other words : stay "helloworld" Of the 2(e) No. 1 position starts , Look for the third time “l” The location of 
7 select instr('helloworld','l',-2,3) from dual; -- Return results :3     in other words : stay "helloworld" The last of 2(l) No. 1 position starts , Go back and look for the third time “l” The location of 
原网站

版权声明
本文为[Zeiyalo]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202161411069316.html