Cursor in stored procedures?
Posted in 2003
Topics: Stored Procedures & SPL
Hi, I am wondering if it is possible to write an stored procedure and use a cursor in it. I googled the net and found only examples and hints how to use cursor in user defined funktions written in C. If anyone has an example how to implement a cursor in SPL it would be very helpful. Greetings, Andreas
"Andreas Schlegel" <schlegelaw@epost.de> wrote in message news:bb30rg$a9p$02$1@news.t-online.com... > Hi, > > I am wondering if it is possible to write an stored procedure and use a > cursor in it. > > I googled the net and found only examples and hints how to use cursor in > user defined funktions written in C. > > If anyone has an example how to implement a cursor in SPL it would be > very helpful. if ur query is static and needs only parameters in the WHERE clause, then a conventional stored procedure will work. However if your query is dynamic (different SELECT fields or FROM tables, or different WHERE columns), u need exec datablade for that.
How about FOREACH?? This gem from TFM (SQL Tutorial)....
CREATE_PROCEDURE increase_by_pct( pct INTEGER )
DEFINE s INTEGER;
FOREACH sal_cursor FOR
SELECT salary INTO s FROM employee
WHERE salary > 35000;
LET s = s + s * ( pct/100 );
UPDATE employee SET salary = s
WHERE CURRENT OF sal_cursor; END FOREACH;
END PROCEDURE;
Jeff
"Andreas Schlegel" <schlegelaw@epost.de> wrote in message
news:bb30rg$a9p$02$1@news.t-online.com...
> Hi,
>
> I am wondering if it is possible to write an stored procedure and use a
> cursor in it.
>
> I googled the net and found only examples and hints how to use cursor in
> user defined funktions written in C.
>
> If anyone has an example how to implement a cursor in SPL it would be
> very helpful.
>
> Greetings,
> Andreas
>