Sybernet / Supplied Functions Reference
Release 3.00
Dec 06, 2002
backwards forwards

HTTP.CHARINDEX

This function searches expression2 for the first occurrence of expression1 and returns an integer representing its starting position. If expression1 is not found, returns 0. If epression1 contains wildcard characters, charindex treats them as literals.

Unlike its Sybase namesake, you may also specify the starting position in expression2 where the search should begin. If not specified, the default offset is 1. This function will also skip occurrences of expresion1 that occur inside of strings. Invalid strings will raise an exception so you are better off using instr() if that is important.


Syntax

Function CHARINDEX
(
    EXPRESSION1                   VARCHAR2
,   EXPRESSION2                   VARCHAR2
,   OFFSET                        BINARY_INTEGER
)
RETURN VARCHAR2;

Parameters

Parameter Description
expression1
 
The pattern whose position you want.
expression2
 
the character expression that is to be searched.
offset
 
The starting offset in expression2 where the search begins.


Returns

0 if expression1 was not found; otherwise, the offset in expression2 where it was found.


Example

The following example illustrates the standard idiom for parsing a comma separated list:

declare
    x binary_integer := 1;
    y binary_integer := 1;
    expression2 varchar2(255) := '"a,b",c,d,e';
begin
    y:=charindex(',',expression2,x);
    while (y > 0) loop
        http.writeln(substr(expression2,x,y-x));
        x:=y+1;
        y:=charindex(',',expression2,x);
    end loop;
    http.writeln(substr(expression2,x));
end;



Sybernet is a trademark of SRI International.
Copyright © 1996-2008 SRI International. All Rights Reserved.
Denis D. Workman / http://Sybernet.sri.com/