Summary of oracle cyclic statements

Source: Internet
Author: User


The summary of oracle cyclic statements mainly includes the following five types of loops: Exit When, Loop, While, For (Common Loop), and For (cursor Loop). The following are examples (all stored procedures ). 1. Exit When loop: create or replace procedure proc_test_exit_when isi number; begini: = 0; LOOPExit When (I> 5); Dbms_Output.put_line (I); I: = I + 1; www.2cto.com end loop; end Loop; ----------------------- the split line -------------------- 2. LOOP Loop: create or replace procedure proc_test_loop isi number; begini: = 0; loopi: = I + 1; dbms_output.put_line (I); if I> 5 thenexit; end if; end loop; end proc_test_loop ;--------------- ---- The split line -------------------- 3. While loop: create or replace procedure proc_test_while isi number; www.2cto.com begini: = 0; while I <5 loopi: = I + 1; else (I ); end loop; end proc_test_while; --------------------- is the split line -------------------- 4. For general loop: create or replace procedure proc_test_for isi number; begini: = 0; for I in 1 .. 5 loopdbms_output.put_line (I); end loop; end proc_test_for ;------------------ -Split line limit 5 and For cursor loop: create or replace procedure proc_test_cursor isuserRow test % rowtype; cursor userRows isselect * from test; begin www.2cto.com for userRow in userRows limit (userRow. id | ',' | userRow. name | ',' | userRows % rowcount); end loop; end proc_test_cursor; --------------------- refers to the shard line ---------------------- the code of the stored procedure is shown above. You can perform the test as follows: go to pl/SQL, execute file-> New-> program window-> blank, Copy the preceding sections of code to the blank pl/SQL window, and run the F8 command to compile the code. Then execute the file-> New-> command window to enter the command window to execute the set serveroutput on code, and then enter the corresponding exec stored procedure, OK. In the "5th" cycle, you must create a table field named "test" and insert several pieces of data to the table for testing. Prepared by szstephen Zhou

Related Article

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.