LOCATE

 

The function LOCATE returns the first starting position of a string in another string. If string1 or string2 is NULL then it returns NULL. If string1 not found in string2 then it returns 0.

SQL Syntax:
 
   LOCATE( string1, string2 [, start] )
Parameters:
 
  string1

Any string expression. This string is searching in string2.

string2

A string that can contain the string from string1.

start

Is the start position to search string1 in string2. If the value not set, NULL or lesser than 1 then the search start at beginning.

Escape Syntax:
 
  {fn LOCATE( string1, string2 [, start] ) }
Return Type:
 
  INT

Alternative Names:

  CHARINDEX This is the equivalent from the MS SQL Server.

Examples:

  • SELECT LOCATE( 'Peter', 'Peter Steve Tom' )

see also:
SQL String Functions


100% pure Java DBMS
Mirror Site