<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Problems with cursors in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/problems-with-cursors/qaa-p/13839724#M4870567</link>
    <description>&lt;P&gt;Try wrapping your code in a BEGIN END block. That is called a "batch" in dbisql-speak... a BEGIN block without the trappings of a stored procedure.&lt;/P&gt;</description>
    <pubDate>Fri, 09 May 2014 08:33:42 GMT</pubDate>
    <dc:creator>Breck_Carter</dc:creator>
    <dc:date>2014-05-09T08:33:42Z</dc:date>
    <item>
      <title>Problems with cursors</title>
      <link>https://community.sap.com/t5/technology-q-a/problems-with-cursors/qaq-p/13839719</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;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:&lt;/P&gt;
&lt;P&gt;prompt&amp;gt;declare curr1 CURSOR FOR select * from test1;&lt;/P&gt;
&lt;P&gt;prompt&amp;gt;open curr1;&lt;/P&gt;
&lt;P&gt;But am getting the error "Cursor has not been declared" ,  SQLCODE=-170 ODBC3 state ="24000"?&lt;/P&gt;
&lt;P&gt;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? &lt;/P&gt;
&lt;P&gt;Machine am working is  - Red Hat Enterprise Linux Server release 6.4&lt;/P&gt;
&lt;P&gt;Database - Sybase IQ 16.0&lt;/P&gt;
&lt;P&gt;Interface - dbisql &lt;/P&gt;
&lt;P&gt;Any help is much appreciated.&lt;/P&gt;
&lt;P&gt;Thanks,
Vaish&lt;/P&gt;</description>
      <pubDate>Wed, 30 Apr 2014 01:50:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/problems-with-cursors/qaq-p/13839719</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2014-04-30T01:50:23Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with cursors</title>
      <link>https://community.sap.com/t5/technology-q-a/problems-with-cursors/qaa-p/13839720#M4870563</link>
      <description>&lt;P&gt;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 &lt;A href="http://dcx.sybase.com/index.html#1201/en/dbreference/declare-cursor-statement.html"&gt;following quote from the docs&lt;/A&gt; applies here, too:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;In a Watcom SQL procedure, trigger, or batch, a DECLARE CURSOR statement must appear with other declarations, immediately following the BEGIN keyword.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;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&lt;/P&gt;
&lt;PRE class="codehilite"&gt;&lt;CODE class="language-sql"&gt;begin
   declare curr1 cursor for select * from test1;
   open curr1;
   lp: loop
    fetch next curr1 into &amp;lt;...&amp;gt;;
    if sqlcode &amp;lt;&amp;gt; 0 then leave lp end if;
    ...
   end loop;
  close curr1;
end


&lt;HR /&gt;
&lt;P&gt;The same is true when you use the &lt;A href="http://dcx.sybase.com/index.html#1201/en/dbreference/for-statement.html"&gt;FOR statement&lt;/A&gt; 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...&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Apr 2014 03:32:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/problems-with-cursors/qaa-p/13839720#M4870563</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2014-04-30T03:32:41Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with cursors</title>
      <link>https://community.sap.com/t5/technology-q-a/problems-with-cursors/qaa-p/13839721#M4870564</link>
      <description>&lt;P&gt;Thanks for your response. But , unfortunately this is not working in dbisql. Infact, begin and then enter, dbisql says syntax error. And the sybase documentation says declare cursor is not present for ISQL. If you know any technique to retrieve one particular record based on row number then please let me know.&lt;/P&gt;
&lt;P&gt;Note: I tried LIMIT and OFFSET, but these 2 keywords are not working in dbisql &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 May 2014 01:09:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/problems-with-cursors/qaa-p/13839721#M4870564</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2014-05-01T01:09:46Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with cursors</title>
      <link>https://community.sap.com/t5/technology-q-a/problems-with-cursors/qaa-p/13839722#M4870565</link>
      <description>&lt;P&gt;What tool are you using? AFAIK, &lt;A href="http://infocenter.sybase.com/help/index.jsp?docset=/com.sybase.infocenter.help.iq.16.0/doc/html/title.html&amp;amp;docSetID=1947"&gt;DBISQL for Sybase IQ&lt;/A&gt; should behave similar to the same tool for SQL Anywhere, and that does not have a "command prompt" but a full SQL statement editor. So you would not have "enter" the BEGIN statement but would execute the whole code block at once.&lt;/P&gt;
&lt;P&gt;Are you using any older command-style tool?&lt;/P&gt;</description>
      <pubDate>Fri, 02 May 2014 03:08:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/problems-with-cursors/qaa-p/13839722#M4870565</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2014-05-02T03:08:49Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with cursors</title>
      <link>https://community.sap.com/t5/technology-q-a/problems-with-cursors/qaa-p/13839723#M4870566</link>
      <description>&lt;P&gt;Am using dbisql to connect to db. And, unfortunately it seems, DECLARE CURSOR statement is not supported outside stored procedure in Sybase IQ16.&lt;/P&gt;</description>
      <pubDate>Thu, 08 May 2014 20:55:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/problems-with-cursors/qaa-p/13839723#M4870566</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2014-05-08T20:55:34Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with cursors</title>
      <link>https://community.sap.com/t5/technology-q-a/problems-with-cursors/qaa-p/13839724#M4870567</link>
      <description>&lt;P&gt;Try wrapping your code in a BEGIN END block. That is called a "batch" in dbisql-speak... a BEGIN block without the trappings of a stored procedure.&lt;/P&gt;</description>
      <pubDate>Fri, 09 May 2014 08:33:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/problems-with-cursors/qaa-p/13839724#M4870567</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2014-05-09T08:33:42Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with cursors</title>
      <link>https://community.sap.com/t5/technology-q-a/problems-with-cursors/qaa-p/13839725#M4870568</link>
      <description>&lt;P&gt;Vaish seems to have tried that, to cite from his first comment here:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Infact, begin and then enter, dbisql says syntax error. &lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What has puzzled me, is the "DBISQL prompt" Vaish has cited in this question and that probably seems to be involved in that test with begin, too.&lt;/P&gt;
&lt;P&gt;That doesn't look like the DBISQL I'm familiar with - but I don't use IQ, so possibly that tool is a different one...&lt;/P&gt;</description>
      <pubDate>Fri, 09 May 2014 08:56:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/problems-with-cursors/qaa-p/13839725#M4870568</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2014-05-09T08:56:49Z</dc:date>
    </item>
  </channel>
</rss>

