Previous Topic: The TRIM FunctionNext Topic: The CHAR_LENGTH Function


The POSITION Function

The POSITION function returns the integer value of the first location of a search character string within a target character string. If the search string does not occur in the target character string, zero is returned. A string of blanks is a valid search string. The syntax of the POSITION function is:

POSITION('search string'/colname  IN  'target string'/colname)

In the following example, the position of a literal string in a column is returned in a select statement:

“SELECT NAME POSITION('CICS' IN RECOV_PROC) FROM SYSTEMS”

This statement returns the following variables for the POSITION column:

In the following example, the position of a column value in a literal value is used in the where clause of a select statement:

“SELECT  NAME  FROM SYSTEMS WHERE  POSITION( NAME IN 'XYZ IMS')
> 0”

Because the NAME column value of IMS does occur in the literal value specified, the NAME='IMS' row is selected.