Locate Function; Considerations For Locate; Result Of Locate; Using Ucase - HP Neoview SQL Reference Manual

Hide thumbs Also See for Neoview SQL:
Table of Contents

Advertisement

LOCATE Function

The LOCATE function searches for a given substring in a character string. If the substring is
found, Neoview SQL returns the character position of the substring within the string. The result
returned by the LOCATE function is equal to the result returned by the POSITION function.
LOCATE is a Neoview SQL extension.
LOCATE (substring-expression,source-expression)
substring-expression
is an SQL character value expression that specifies the substring to search for in
source-expression. The substring-expression cannot be NULL. See
Value Expressions" (page
source-expression
is an SQL character value expression that specifies the source string. The
source-expression cannot be NULL. See
Neoview SQL returns the result as a 2-byte signed integer with a scale of zero. If
substring-expression is not found in source-expression, Neoview SQL returns 0.

Considerations for LOCATE

Result of LOCATE

If the length of source-expression is zero and the length of substring-expression is
greater than zero, Neoview SQL returns 0. If the length of substring-expression is zero,
Neoview SQL returns 1.
If the length of substring-expression is greater than the length of source-expression,
Neoview SQL returns 0. If source-expression is a null value, Neoview SQL returns a null
value.

Using UCASE

To ignore case in the search, use the UCASE function (or the LCASE function) for both the
substring-expression and the source-expression.

Examples of LOCATE

Return the value 8 for the position of the substring 'John' within the string:
LOCATE ('John','Robert John Smith')
Suppose that the EMPLOYEE table has an EMPNAME column that contains both the first
and last names. This SELECT statement returns all records in table EMPLOYEE that contain
the substring 'SMITH', regardless of whether the column value is in uppercase or lowercase
characters:
SELECT * FROM persnl.employee
WHERE LOCATE ('SMITH',UCASE(empname)) > 0 ;
208).
"Character Value Expressions" (page
"Character
208).
LOCATE Function
351

Advertisement

Table of Contents
loading

Table of Contents