|
Sybernet / Supplied Functions Reference
Release 3.00 Dec 06, 2002 |
|
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.
Function CHARINDEX
(
EXPRESSION1 VARCHAR2
, EXPRESSION2 VARCHAR2
, OFFSET BINARY_INTEGER
)
RETURN VARCHAR2;
| 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. |
0 if expression1 was not found; otherwise, the offset in expression2 where it was found.
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;