<?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: Can cursor be used inside a while statement? in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/can-cursor-be-used-inside-a-while-statement/qaa-p/13840763#M4871606</link>
    <description>&lt;P&gt;FWIW, if you are about to call a DDL statement inside the loop (say, ALTER TABLE), it is way easier to use a FOR loop - cf. &lt;A href="http://sqlanywhere-forum.sap.com/questions/13227/execute-statement-in-the-loop"&gt;this FAQ&lt;/A&gt; on a similar issue...&lt;/P&gt;</description>
    <pubDate>Fri, 09 Nov 2012 14:56:22 GMT</pubDate>
    <dc:creator>VolkerBarth</dc:creator>
    <dc:date>2012-11-09T14:56:22Z</dc:date>
    <item>
      <title>Can cursor be used inside a while statement?</title>
      <link>https://community.sap.com/t5/technology-q-a/can-cursor-be-used-inside-a-while-statement/qaq-p/13840759</link>
      <description>&lt;P&gt;Hello all, &lt;/P&gt;
&lt;P&gt;Does anyone know what's wrong with the following WHILE statement? &lt;/P&gt;
&lt;P&gt;I am trying to write a script on Sybase Anywhere 12.0.1 to alter all integer columns to bigint columns. I wrote the script like below(this is a simplified version). When I ran it, it was always telling me there was a syntax error near 'begin' on line 8. If I took the 'begin ... end' out of the while statement, it would say there was a syntax error near 'fetch' on line 10. What's wrong with while statement? Is it because I have to use loop...end loop for cursor as I saw some examples?&lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="mi"&gt;1&lt;/SPAN&gt;   &lt;SPAN class="k"&gt;BEGIN&lt;/SPAN&gt;
&lt;SPAN class="mi"&gt;2&lt;/SPAN&gt;       &lt;SPAN class="n"&gt;DECLARE&lt;/SPAN&gt; &lt;SPAN class="n"&gt;cur&lt;/SPAN&gt; &lt;SPAN class="n"&gt;CURSOR&lt;/SPAN&gt; &lt;SPAN class="n"&gt;FOR&lt;/SPAN&gt; &lt;SPAN class="nb"&gt;select&lt;/SPAN&gt; &lt;SPAN class="n"&gt;table_name&lt;/SPAN&gt; &lt;SPAN class="n"&gt;from&lt;/SPAN&gt; &lt;SPAN class="n"&gt;SYSTAB&lt;/SPAN&gt;&lt;SPAN class="p"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="mi"&gt;3&lt;/SPAN&gt;       &lt;SPAN class="n"&gt;DECLARE&lt;/SPAN&gt; &lt;SPAN class="nv"&gt;@tablename&lt;/SPAN&gt; &lt;SPAN class="n"&gt;NCHAR&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="mi"&gt;100&lt;/SPAN&gt;&lt;SPAN class="p"&gt;);&lt;/SPAN&gt;
&lt;SPAN class="mi"&gt;4&lt;/SPAN&gt;
&lt;SPAN class="mi"&gt;5&lt;/SPAN&gt;       &lt;SPAN class="nb"&gt;open&lt;/SPAN&gt; &lt;SPAN class="n"&gt;cur&lt;/SPAN&gt; &lt;SPAN class="n"&gt;with&lt;/SPAN&gt; &lt;SPAN class="n"&gt;hold&lt;/SPAN&gt;&lt;SPAN class="p"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="mi"&gt;6&lt;/SPAN&gt;       &lt;SPAN class="n"&gt;fetch&lt;/SPAN&gt; &lt;SPAN class="n"&gt;cur&lt;/SPAN&gt; &lt;SPAN class="n"&gt;into&lt;/SPAN&gt; &lt;SPAN class="nv"&gt;@tablename&lt;/SPAN&gt;&lt;SPAN class="p"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="mi"&gt;7&lt;/SPAN&gt;       &lt;SPAN class="n"&gt;WHILE&lt;/SPAN&gt; &lt;SPAN class="nv"&gt;@@fetch_status&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="mi"&gt;0&lt;/SPAN&gt;
&lt;SPAN class="mi"&gt;8&lt;/SPAN&gt;       &lt;SPAN class="n"&gt;begin&lt;/SPAN&gt;
&lt;SPAN class="mi"&gt;9&lt;/SPAN&gt;           &lt;SPAN class="o"&gt;--&lt;/SPAN&gt; &lt;SPAN class="k"&gt;do&lt;/SPAN&gt; &lt;SPAN class="n"&gt;something&lt;/SPAN&gt; &lt;SPAN class="n"&gt;with&lt;/SPAN&gt; &lt;SPAN class="n"&gt;cursor&lt;/SPAN&gt;
&lt;SPAN class="mi"&gt;10&lt;/SPAN&gt;          &lt;SPAN class="n"&gt;fetch&lt;/SPAN&gt; &lt;SPAN class="n"&gt;cur&lt;/SPAN&gt; &lt;SPAN class="n"&gt;into&lt;/SPAN&gt; &lt;SPAN class="nv"&gt;@tablename&lt;/SPAN&gt;&lt;SPAN class="p"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="mi"&gt;11&lt;/SPAN&gt;      &lt;SPAN class="n"&gt;end&lt;/SPAN&gt;
&lt;SPAN class="mi"&gt;12&lt;/SPAN&gt;       &lt;SPAN class="n"&gt;CLOSE&lt;/SPAN&gt; &lt;SPAN class="n"&gt;int_cursor&lt;/SPAN&gt;&lt;SPAN class="p"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="mi"&gt;13&lt;/SPAN&gt;  &lt;SPAN class="k"&gt;END&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 09 Nov 2012 13:59:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/can-cursor-be-used-inside-a-while-statement/qaq-p/13840759</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-11-09T13:59:48Z</dc:date>
    </item>
    <item>
      <title>Re: Can cursor be used inside a while statement?</title>
      <link>https://community.sap.com/t5/technology-q-a/can-cursor-be-used-inside-a-while-statement/qaa-p/13840760#M4871603</link>
      <description>&lt;P&gt;I guess you're mixing Watcom-SQL and T-SQL dialects here.&lt;/P&gt;
&lt;P&gt;As most of the code is Watcom-SQL, you should be able to simply adapt the WHILE loop to Watcom-SQL syntax:&lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="n"&gt;WHILE&lt;/SPAN&gt; &lt;SPAN class="o"&gt;@@&lt;/SPAN&gt;&lt;SPAN class="n"&gt;fetch_status&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="mi"&gt;0&lt;/SPAN&gt; &lt;SPAN class="n"&gt;LOOP&lt;/SPAN&gt;
   &lt;SPAN class="c1"&gt;-- do something with cursor&lt;/SPAN&gt;
   &lt;SPAN class="k"&gt;fetch&lt;/SPAN&gt; &lt;SPAN class="n"&gt;cur&lt;/SPAN&gt; &lt;SPAN class="k"&gt;into&lt;/SPAN&gt; &lt;SPAN class="o"&gt;@&lt;/SPAN&gt;&lt;SPAN class="n"&gt;tablename&lt;/SPAN&gt;&lt;SPAN class="p"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="k"&gt;END&lt;/SPAN&gt; &lt;SPAN class="n"&gt;LOOP&lt;/SPAN&gt;&lt;SPAN class="p"&gt;;&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 09 Nov 2012 14:14:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/can-cursor-be-used-inside-a-while-statement/qaa-p/13840760#M4871603</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2012-11-09T14:14:18Z</dc:date>
    </item>
    <item>
      <title>Re: Can cursor be used inside a while statement?</title>
      <link>https://community.sap.com/t5/technology-q-a/can-cursor-be-used-inside-a-while-statement/qaa-p/13840761#M4871604</link>
      <description>&lt;P&gt;Thanks for the quick answer! I changed it to while loop...end loop.  It passed that point but it's now complaining a syntax error near 'close' on line 12. The 'int_cursor' should be 'cur'. Any idea?&lt;/P&gt;</description>
      <pubDate>Fri, 09 Nov 2012 14:22:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/can-cursor-be-used-inside-a-while-statement/qaa-p/13840761#M4871604</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-11-09T14:22:51Z</dc:date>
    </item>
    <item>
      <title>Re: Can cursor be used inside a while statement?</title>
      <link>https://community.sap.com/t5/technology-q-a/can-cursor-be-used-inside-a-while-statement/qaa-p/13840762#M4871605</link>
      <description>&lt;P&gt;I missed a semicolon after END LOOP. That's it.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Nov 2012 14:27:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/can-cursor-be-used-inside-a-while-statement/qaa-p/13840762#M4871605</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-11-09T14:27:08Z</dc:date>
    </item>
    <item>
      <title>Re: Can cursor be used inside a while statement?</title>
      <link>https://community.sap.com/t5/technology-q-a/can-cursor-be-used-inside-a-while-statement/qaa-p/13840763#M4871606</link>
      <description>&lt;P&gt;FWIW, if you are about to call a DDL statement inside the loop (say, ALTER TABLE), it is way easier to use a FOR loop - cf. &lt;A href="http://sqlanywhere-forum.sap.com/questions/13227/execute-statement-in-the-loop"&gt;this FAQ&lt;/A&gt; on a similar issue...&lt;/P&gt;</description>
      <pubDate>Fri, 09 Nov 2012 14:56:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/can-cursor-be-used-inside-a-while-statement/qaa-p/13840763#M4871606</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2012-11-09T14:56:22Z</dc:date>
    </item>
  </channel>
</rss>

