oracle instr() and substr() functions

In Oracle,
you can use the instr function to judge a string to determine whether it contains the specified character.
Finds the specified character in a string and returns the position of the specified character found.
Syntax:
instr(sourceString,destString,start,appearPosition)

instr ('source string' , 'target string' , 'starting position', 'the first occurrence')
where sourceString represents the source string;
destString represents the substring to be searched from the source string;
start represents the searched The starting position, this parameter is optional, the default is 1;
appearPosition represents the destString that you want to find the first occurrence from the source character, this parameter is also optional, the default is 1,
if the value of start is negative, it means from the right The lookup is done to the left, but the location data is still calculated from left to right.
The return value is: the position of the found string.
-------------------------------------------------- -------------
For the instr function, we often use it like this: Find the position of the specified substring from a string. For example:
SQL> select instr('abcdefgh','de') position from dual;
POSITION
----------
   4
starts from 1 and counts d and ranks fourth so return 4

SQL>select instr('abcdefghbc','bc',3) position from dual;
POSITION
----------
  9
The 3rd character is c from the 3rd character, so it starts from 3 Find bc in the following strings, return 9
-----------------------------
Starting from the first character, find the second occurrence of the sub String position
SQL> select instr('qinyinglianqin','qin', 1, 2) position from dual;
POSITION
----------
  12
-------------- -------------------------------------------------- ------

SUBSTR() function  
1. Use: It returns a substring from a given character expression or memo field.  
 
2. Syntax format: SUBSTR(cExpression, nStartPosition[, nCharactersReturned])   
where cExpression specifies the character expression or memo field from which the string is to be returned;
nStartPosition is used to specify the returned string in the character expression or memo field. Position,
nCharactersReturned is used to specify the number of characters returned. By default, all characters before the end of the value of the character expression are returned.  
 
3. Example: STORE'abcdefghijlkm' To mystring   
SUBSTR(mystring ,1,5) Display "abcde" 1 The characters intercepted from the first character, including the first character 
SUBSTR(mystring ,6) Display "fghijklm"   
SUBSTR (mystring,-2) display "km" The rightmost character is -1, the rightmost left character is -2, and then the default is to take all the remaining characters from left to left
SUBSTR(mystrng,-4) display " jlkm”

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326751110&siteId=291194637