Parsing Strings in Stored Procedures
Posted in 2000
Topics: Stored Procedures & SPL
In a stored procedure, I was hoping to be able to strip sets of characters out of a comma delimited line. So far, it looks like the only way I can do this is write a C program, which parses the data for the stored procedure. I have seen a few notes about the use of collections, but I haven't seen any notes, examples, or documentation that could help me. Does anyone know how I could parse such a line in an Informix stored procedure, without calling a C program? An example would be greatly appreciated. Using Informix IUS 9.14. Thank you, Karl Van Neste
This is one approach we have used in the past, it is not the most efficient
thing in the world:
create procedure parser(c_in varchar(100))
returning varchar(100);define c_out varchar(100);
define x int;
define y int;
define m int;
let m=octet_length(c_in);
let x=1;
let y=1;
while y<=m+1
if y>m or substr(c_in,y,1)=","
c_out=substr(c_in,x,y-x);
return c_out;
let x=y+1;
end if;
let y=y+1;
end while;
c_out=substr(c_in,x,y-x);
return c_out;
end procedure;
execute procedure parser("one,two,three");
The procedure should return:
one
two
three
I did not get a chance to test this particular version, but it should be
pretty close.
Jay Buckler
Penny & Karl Van Neste <vanneste@erols.com> wrote in message
news:3878D692.F8698CE5@erols.com...
> In a stored procedure, I was hoping to be able to strip sets of
> characters out of a comma delimited line. So far, it looks like the
> only way I can do this is write a C program, which parses the data for
> the stored procedure. I have seen a few notes about the use of
> collections, but I haven't seen any notes, examples, or documentation
> that could help me. Does anyone know how I could parse such a line in
> an Informix stored procedure, without calling a C program? An example
> would be greatly appreciated. Using Informix IUS 9.14. Thank you,
> Karl Van Neste
>