The USING variable-name clause on the DECLARE CURSOR command can be used for
this.
create function do_my_stuff(in qry long varchar)
returns int
begin
declare crsr cursor using qry;
declare c1 integer;
declare c2 integer;
declare c3 varchar(128)
open crsr;
lp: loop
fetch crsr into c1,c2,c3;
if SQLCODE <> 0 then leave lp end if;
// do something with c1,c2,c3
end loop;
close crsr;
end
This works because, as you pointed out "the column's datatype on select
would be fixed".
--
Reg Domaratzki, Sybase iAnywhere Solutions
Sybase Certified Professional - Sybase ASA Developer Version 8
Please reply only to the newsgroup
iAnywhere Developer Community : http://www.ianywhere.com/developer
ASA Patches and EBFs : http://downloads.sybase.com/swx/sdmain.stm
-> Choose SQL Anywhere Studio
-> Set "Platform Preview" and "Time Frame" to ALL
"Jayvee Vibar" <jayvee (AT) digitelone (DOT) com> wrote
Quote:
ASA 7.0.3
Hello,
How can I create a dynamic sql with cursors?
Ex.
declare bcur dynamic scroll cursor for select number(*) as
rowid,bk.book_id,title from books as bk join accession as ac order by
title asc;
the columns's datatype on select would be fixed say integer(rowid),
integer(book_id), char(title), but I would like the contents of the sql
to vary ex. select from other table and also with different where
condition but using the same handle *bcur*.
Thanks for any help. |