SQL LOCATE scalar function in DB2 for i SQL

SQL LOCATE scalar function in DB2 for i SQL
SQL LOCATE scalar function in DB2 for i SQL, sql function, ibmi db2
SQL LOCATE scalar function in DB2 for i SQL

LOCATE

The LOCATE function returns the position at which the first occurrence of search string starts within source string. If search string is not found then this function returns zero.

Syntax

LOCATE(search-string, source-string, start<optional>)

When optional start is specified then it indicates the character position in the source string at which the search is to start.

Example

SELECT locate('A', 'TEST'),  
       locate('T', 'TEST'),  
       locate('E', 'TEST'),  
       locate('T', 'TEST', 2)
  FROM sysibm.SYSDUMMY1      

Output:

       LOCATE          LOCATE          LOCATE          LOCATE
            0               1               2               4

Post a Comment

© AS400 and SQL Tricks. All rights reserved. Developed by Jago Desain