REGEXP_INSTR

2023-10-27 09:57:43  Updated

Syntax

REGEXP_INSTR(expr, pat [, pos [, occurrence [, return_option [, match_type ]]]])

Purpose

You can call this function to return the start position of the substring in the expr expression that matches the pat expression. If no such substrings exist, the function returns 0. If expr or pat is NULL, the function returns NULL. The return value of the position starts from 1.

  • pos indicates the start position for character search in the expr expression. The default value is 1.

  • occurrence specifies the ordinal number of occurrence of pat in expr. The default value is 1.

  • return_option specifies the type of the return value. The default value is 0.

    • The value 0 indicates that REGEXP_INSTR() returns the position of the first character of the substring that matches pat.

    • The value 1 indicates that REGEXP_INSTR() returns the position of the last character of the substring that matches pat.

  • match_type indicates the matching rule. For information about matching rules, see REGEXP_LIKE.

Examples

obclient> SELECT REGEXP_INSTR('ocean base oceanbase', 'ocean');
+-----------------------------------------------+
 REGEXP_INSTR('ocean base oceanbase', 'ocean') 
+-----------------------------------------------+
                                             1 
+-----------------------------------------------+
1 row in set (0.01 sec)

obclient> SELECT REGEXP_INSTR('ocean base oceanbase', 'ocean',2);
+-------------------------------------------------+
 REGEXP_INSTR('ocean base oceanbase', 'ocean',2) 
+-------------------------------------------------+
                                               12 
+-------------------------------------------------+
1 row in set (0.00 sec)

obclient> SELECT REGEXP_INSTR('ocean base oceanbase', 'ocean',1,2);
+---------------------------------------------------+
 REGEXP_INSTR('ocean base oceanbase', 'ocean',1,2) 
+---------------------------------------------------+
                                                12 
+---------------------------------------------------+
1 row in set (0.00 sec)

obclient> SELECT REGEXP_INSTR('ocean base oceanbase', 'ocean',1,2,1);
+-----------------------------------------------------+
 REGEXP_INSTR('ocean base oceanbase', 'ocean',1,2,1) 
+-----------------------------------------------------+
                                                  17 
+-----------------------------------------------------+
1 row in set (0.01 sec) 

Contact Us