LOCATE function

Function

The LOCATE function returns a 64 bit signed integer containing the position of the specified string in a LONG VARCHAR column. LOCATE returns a 32 bit signed integer position for CHAR and VARCHAR columns.

Syntax

LOCATElong-varchar-column, string-expression
[, numeric-expression ] )

Parameters

long-varchar-column The name of the LONG VARCHAR column to search.

string-expression The string for which you are searching. This string is limited to 255 bytes.

numeric-expression The character position or offset at which to begin the search in the string. The numeric-expression is a 64 bit signed integer for LONG VARCHAR and LONG BINARY columns and is a 32 bit signed integer for CHAR, VARCHAR, and BINARY columns. The first character is position 1. If the starting offset is negative, LOCATE returns the last matching string offset, rather than the first. A negative offset indicates how much of the end of the string to exclude from the search. The number of characters excluded is calculated as ( -1 * offset ) - 1.

Usage

See also

For a full description and examples of the LOCATE function, see “LOCATE function [String]” in Chapter 4, “SQL Functions” of Reference: Building Blocks, Tables, and Procedures.