dbTalk Databases Forums  

Dynamic sql on cursor inside stored procedures?

sybase.public.sqlanywhere.general sybase.public.sqlanywhere.general


Discuss Dynamic sql on cursor inside stored procedures? in the sybase.public.sqlanywhere.general forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Jayvee Vibar
 
Posts: n/a

Default Dynamic sql on cursor inside stored procedures? - 12-08-2003 , 08:58 PM






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.


Reply With Quote
  #2  
Old   
Reg Domaratzki
 
Posts: n/a

Default Re: Dynamic sql on cursor inside stored procedures? - 12-09-2003 , 08:21 AM






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.




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.