INSTR 함수

설명

INSTR 함수는 POSITION 함수와 유사하게 문자열 string 내에서 문자열 substring의 위치를 반환한다. 단, INSTR 함수는 substring의 검색을 시작할 위치를 지정할 수 있으므로 중복된 substring을 검색할 수 있다.

문자 단위가 아닌 바이트 단위로 위치를 반환한다는 점을 주의한다. 멀티바이트 문자 세트에서는 한 문자를 표현하는 바이트 수가 다르므로 반환되는 결과 값이 다를 수 있다.

구문

INSTR( string , substring [, position] )

 

string , substring :

• character string

NULL

position :

INT

NULL

예제

--character set is euc-kr for Korean characters

--it returns position of the first 'b'

SELECT INSTR ('12345abcdeabcde','b');

 

===================================

                                  7

 

-- it returns position of the first '나' on double byte charset

SELECT INSTR ('12345가나다라마가나다라마', '나' );

=================================

                                8

 

-- it returns position of the second '나' on double byte charset

SELECT INSTR ('12345가나다라마가나다라마', '나', 16 );

=================================

                               18

 

--it returns position of the 'b' searching from the 8th position

SELECT INSTR ('12345abcdeabcde','b', 8);

 

===================================

                                 12

 

--it returns position of the 'b' searching backwardly from the end

SELECT INSTR ('12345abcdeabcde','b', -1);

 

====================================

                                  12

 

--it returns position of the 'b' searching backwardly from a specified position

SELECT INSTR ('12345abcdeabcde','b', -8);

 

====================================

                                   7