Using Java Types and Methods in SQL
DECLARE to_be_searched java.lang.String;
DECLARE search_for java.lang.String;
DECLARE last_index INTEGER;
= NEW java.lang.String ( '56785678' );
= NEW java.lang.String ( '5678' );
= to_be_searched.lastIndexOf
MESSAGE 'test: last_index = ', last_index;
Notes:
The lastIndexOf() method is part of the JDK (Java Development Kit) that comes with ASA. Unlike ASA's own CHARINDEX() function, lastIndexOf() finds the position of the last occurrence of a search string inside another string. This example shows how lastIndexOf() can be called directly from a Watcom SQL script run via DBISQL. It displays "test: last_index = 4" on the ASA server console. Note that Java starts counting at 0 when it comes to character positions in strings.