The substr() function and instr() function in Oracle use

1) Substr function format (commonly known as: character interception function)

  Format 1: substr(string string, int a, int b);

  Format 2: substr(string string, int a) ;

Explanation:

Format 1

1. The character that string needs to be intercepted String
2. a The start position of the string to be intercepted (Note: when a is equal to 0 or 1, it is intercepted from the first bit)
3. b The length of the string to be intercepted

Format 2

1. string The string to be intercepted
2. a can be understood as intercepting all subsequent strings starting from the a-th character.

2) Format of the instr() function (commonly known as: character search function)

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

Format 2: instr( string1, string2 [, start_position [, nth_appearance ] ] ) / instr(source string, target string, starting position, matching sequence number)

analysis: the value of string2 is to be searched in string1, which is retrieved from the value (ie: position) given by start_position in string1, and the first nth_appearance(several) occurrences of string2.

Note: In Oracle/PLSQL, the instr function returns the position of the string to be intercepted in the source string. It is retrieved only once, that is, from the beginning of the character to the end of the character.




Note: The fuzzy query like in MySQL and the instr() function in oracle have the same query effect; as follows:

select * from tableName a where name like '%helloworld%';
select * from tableName a where instr(name, 'helloworld')>0; --The effect of these two statements is the same. When the amount of


data is large, it is recommended that oracle use instr instead of not like when like must be used;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325974111&siteId=291194637