Subject | Re: POSITION |
---|---|
Author | rodries2 |
Post date | 2005-02-17T09:48:25Z |
--- In firebird-support@yahoogroups.com, "Dion Oliphant"
<doliphant@s...> wrote:
see http://www.volny.cz/iprenosil/interbase/ip_ib_code_string.htm
CREATE PROCEDURE Pos (SubStr VARCHAR(100), Str VARCHAR(100))
RETURNS (Pos INTEGER) AS
DECLARE VARIABLE SubStr2 VARCHAR(201); /* 1 + SubStr-lenght + Str-
length */
DECLARE VARIABLE Tmp VARCHAR(100);
BEGIN
IF (SubStr IS NULL OR Str IS NULL)
THEN BEGIN Pos = NULL; EXIT; END
SubStr2 = SubStr || '%';
Tmp = '';
Pos = 1;
WHILE (Str NOT LIKE SubStr2 AND Str NOT LIKE Tmp) DO BEGIN
SubStr2 = '_' || SubStr2;
Tmp = Tmp || '_';
Pos = Pos + 1;
END
IF (Str LIKE Tmp) THEN Pos = 0;
END
Example of calling from another stored procedure:
EXECUTE PROCEDURE Pos 'bc', 'abcdefghij' RETURNING_VALUES :cad_pos;
Regards
<doliphant@s...> wrote:
> Hi,DSQL.
>
> Is it possible to find the occurrence of a char in a string using
> Iehere))
> SELECT SUBSTRING(aWord FROM 1 TO (need to insert a char position
> from aTable, or will I need to use an SP. Basically I need to splita
> string(CSV) into its substrings.Hi Dion
>
> Many Thanks,
> Dion.
see http://www.volny.cz/iprenosil/interbase/ip_ib_code_string.htm
CREATE PROCEDURE Pos (SubStr VARCHAR(100), Str VARCHAR(100))
RETURNS (Pos INTEGER) AS
DECLARE VARIABLE SubStr2 VARCHAR(201); /* 1 + SubStr-lenght + Str-
length */
DECLARE VARIABLE Tmp VARCHAR(100);
BEGIN
IF (SubStr IS NULL OR Str IS NULL)
THEN BEGIN Pos = NULL; EXIT; END
SubStr2 = SubStr || '%';
Tmp = '';
Pos = 1;
WHILE (Str NOT LIKE SubStr2 AND Str NOT LIKE Tmp) DO BEGIN
SubStr2 = '_' || SubStr2;
Tmp = Tmp || '_';
Pos = Pos + 1;
END
IF (Str LIKE Tmp) THEN Pos = 0;
END
Example of calling from another stored procedure:
EXECUTE PROCEDURE Pos 'bc', 'abcdefghij' RETURNING_VALUES :cad_pos;
Regards