Am new to Sybase IQ 16.0 database(moving from postgresql). Am trying to create a cursor and fetch data. These are the commands I tried:
prompt>declare curr1 CURSOR FOR select * from test1;
But am getting the error "Cursor has not been declared" , SQLCODE=-170 ODBC3 state ="24000"?
My doubt is,Can I create a cursor and use it outside the function ? Or, in Sybase there is no way to declare and use cursor outside functions directly?
Machine am working is - Red Hat Enterprise Linux Server release 6.4
Database - Sybase IQ 16.0
Interface - dbisql
Any help is much appreciated.
Can't really tell whether this is different in IQ than in SQL Anywhere, but as SQL Anywhere seems to be used as the IQ query/parsing engine, I guess the following quote from the docs applies here, too:
That is, you can use cursors outside stored functions and stored procedures but you need to put them in a code block, i.e. something like
The same is true when you use the FOR statement that combines declaring, opening and fetching through a cursor in a handy control structure... - Personally, I prefer FOR mostly all the time over an explicit DECLARE/OPEN/FETCH/CLOSE sequence...