ORACLE statement Loop

Source: Internet
Author: User


Oracle loop Statement 1. Exit When LOOP: www.2cto.com SQL code declare -- Local variables here I integer; begin I: = 0; LOOP Exit When (I> 5); Dbms_Output.put_line (I ); i: = I + 1; end loop; end; 2. Loop Java code declare -- Local variables here I integer; begin I: = 0; loop I: = I + 1; dbms_output.put_line (I); if I> 5 then exit; end if; end loop; end; www.2cto.com 3. While loop: SQL code declare -- Local variables here I integer; begin I: = 0; while I <5 loop I: = I + 1; dbms_output.put_line (I); end loop; end; 4. For general loop: SQL code declare -- Local variables here I integer; begin I: = 0; for I in 1 .. 5 loop dbms_output.put_line (I); end loop; end; www.2cto.com 5. For cursor loop: Prepare the data SQL code -- create table test (id number ); -- insert data declare -- Local variables here I integer; begin I: = 0; for I in 1 .. 5 loop insert into test values (I); end loop; www.2cto.com end; loop SQL code declare -- Local variables here begin for c_test in (select * from test) loop dbms_output.put_line (c_test.id ); end loop; end;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.