trap or bug when using CONTINUE in Oracle 11g

來源:互聯網
上載者:User

CONTINUE is a new feature brought in Oracle 11g, but there is a trap or bug need to pay attention, see the following code scrap:

DECLARE<br /> CURSOR dept_cur IS<br /> SELECT deptno<br /> ,dname<br /> ,loc<br /> FROM scott.dept;<br /> TYPE dept_tab IS TABLE OF dept_cur%ROWTYPE INDEX BY BINARY_INTEGER;<br /> l_dept_tab dept_tab;<br />BEGIN</p><p> --EXECUTE IMMEDIATE 'ALTER SESSION SET PLSQL_OPTIMIZE_LEVEL = 1';<br /> --http://pbarut.blogspot.com/2009/04/caution-for-loop-and-continue-in-oracle.html</p><p> dbms_output.put_line('==========OracleVersion=========');<br /> FOR ver_rec IN (SELECT banner<br /> FROM v$version)<br /> LOOP<br /> dbms_output.put_line(ver_rec.banner);<br /> END LOOP;</p><p> --review test data<br /> dbms_output.put_line('==========dept_loop0=========');<br /> <<dept_loop0>><br /> FOR dept_rec IN dept_cur<br /> LOOP<br /> dbms_output.put_line(dept_rec.deptno || ', ' || dept_rec.dname || ', ' ||<br /> dept_rec.loc);<br /> END LOOP dept_loop0;</p><p> --CONTINUE in implicit cursor<br /> dbms_output.put_line('==========dept_loop1=========');<br /> <<dept_loop1>><br /> FOR dept_rec IN dept_cur<br /> LOOP<br /> IF (dept_rec.deptno = '30')<br /> THEN<br /> continue dept_loop1;<br /> END IF;<br /> dbms_output.put_line(dept_rec.deptno || ', ' || dept_rec.dname || ', ' ||<br /> dept_rec.loc);<br /> END LOOP dept_loop1;</p><p> --CONTINUE in explicit cursor<br /> dbms_output.put_line('==========dept_loop2=========');<br /> OPEN dept_cur;<br /> FETCH dept_cur BULK COLLECT<br /> INTO l_dept_tab;<br /> CLOSE dept_cur;<br /> <<dept_loop2>><br /> FOR i IN 1 .. l_dept_tab.COUNT<br /> LOOP<br /> IF (l_dept_tab(i).deptno = '30')<br /> THEN<br /> continue dept_loop2;<br /> END IF;<br /> dbms_output.put_line(l_dept_tab(i).deptno || ', ' || l_dept_tab(i)<br /> .dname || ', ' || l_dept_tab(i).loc);<br /> END LOOP dept_loop2;<br />END;<br />

 

Output:

==========OracleVersion=========<br />Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production<br />PL/SQL Release 11.1.0.7.0 - Production<br />CORE11.1.0.7.0Production<br />TNS for Solaris: Version 11.1.0.7.0 - Production<br />NLSRTL Version 11.1.0.7.0 - Production<br />==========dept_loop0=========<br />10, ACCOUNTING, NEW YORK<br />20, RESEARCH, DALLAS<br />30, SALES, CHICAGO<br />40, OPERATIONS, BOSTON<br />50, name1, loc1<br />51, name1, name1<br />52, loc1, loc1<br />==========dept_loop1=========<br />10, ACCOUNTING, NEW YORK<br />20, RESEARCH, DALLAS<br />==========dept_loop2=========<br />10, ACCOUNTING, NEW YORK<br />20, RESEARCH, DALLAS<br />40, OPERATIONS, BOSTON<br />50, name1, loc1<br />51, name1, name1<br />52, loc1, loc1<br />

 

As you see, CONTINUE didn't work correctly in implicit cursor loop!!!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.