Declare cursor in a store procedure?
Posted in 1999
Topics: Stored Procedures & SPL
I read serveral of Informix SQL/SPL programming books. All these books are always talked declare cursor and store procedure in different chapters. I want to declare a cursor in a store procedure. But I got the all syntax error messages for those PREPARE DECLARE OPEN FETCH etc. statements. I did the same program in Sybase without problems. Can anyone tell me Informix allows me do the same thing? Thank you! -- RC
Ruiming Chen wrote: > > I read serveral of Informix SQL/SPL programming books. All these > books are always talked declare cursor and store procedure in > different chapters. Two different languages, albeit with a good deal in common. > I want to declare a cursor in a store procedure. But I got the all > syntax error messages for those > > PREPARE > DECLARE > OPEN > FETCH > etc. > > statements. Those are ESQL/C statements rather than pure SQL statements; they are not SPL statements. Please read the section on FOREACH in the SPL chapter of the manual. -- Jonathan Leffler (jleffler@informix.com, jleffler@earthlink.net) Guardian of DBD::Informix v0.60 -- see http://www.perl.com/CPAN #include <disclaimer.h>
The floowing example reads through a table and assignes an
incrementing value to an INTEGER field in each record:
create procedure update_rsn(n_next_rsn integer)
RETURNING integer;
define s_rsn integer;
define s_junk integer;
if n_next_rsn is not NULL then
let s_rsn = n_next_rsn;
else
let s_rsn = 0;
end if
foreach cursor1 for
select employee_rsn into s_junk from employee
let s_rsn = s_rsn + 1;
update employee
set disp_call_sgn = s_rsn
where current of cursor1;
end foreach
return s_rsn;
end procedure;