ORACLE - String Functions : Instr

The instr function returns the location of a substring in a string.
The syntax is:
instr( stringA, stringB [, start_position [, nth_appearance ] ] )
stringA is the string to search.
stringB is the substring to search for in stringA .
start_position is the position in stringA where the search will start. This argument is optional. If omitted, it defaults to 1. The first position in the string is 1. If the start_position is negative, the function counts back start_position number of characters from the end of stringA and then searches towards the beginning of stringA .
nth_appearance is the nth appearance of stringB. This is optional. If omitted, it defaults to 1.

For example:
instr('hello word hello', 'e') would return 2; the first occurrence of 'e'
instr('hello word hello', 'e', 1, 1) would return 2; the first occurrence of 'e'
instr('hello word hello', 'e', 1, 2) would return 13; the second occurrence of 'e'
instr('hello word hello', 'e', -3, 2) would return 2.
instr('hello word hello', 'X', 1, 1) would return 0.

No hay comentarios: