Oracle Circular Statement Summary ____oracle

Source: Internet
Author: User

There are five main loops: Exit when, loop, while, for (normal loop), for (cursor loop), and below for example one by one (all stored procedures).


1, Exit when cycle:
Create or replace procedure Proc_test_exit_when is
I number;
Begin
i:=0;
LOOP
Exit when (i>5);
Dbms_output.put_line (i);
i:=i+1;
End LOOP;
End Proc_test_exit_when;
—————————————————— – I'm a split-line —————————————————————

2. Loop loop:
Create or replace procedure Proc_test_loop is
I number;
Begin
i:=0;
Loop
i:=i+1;
Dbms_output.put_line (i);
If I>5 Then
Exit
End If;
End Loop;
End Proc_test_loop;
—————————————————— – I'm a split-line —————————————————————

3, while loop:
Create or replace procedure Proc_test_while is
I number;
Begin
i:=0;
While I<5 loop
i:=i+1;
Dbms_output.put_line (i);
End Loop;
End Proc_test_while;
—————————————————— – I'm a split-line —————————————————————

4. For general circulation:
Create or replace procedure Proc_test_for is
I number;
Begin
i:=0;
For I in 1..5 loop
Dbms_output.put_line (i);
End Loop;
End Proc_test_for;
—————————————————— – I'm a split-line —————————————————————

5. For cursor loops:
Create or replace procedure Proc_test_cursor is
Userrow Test%rowtype;
Cursor Userrows is
SELECT * from Test;
Begin
For Userrow in Userrows loop
Dbms_output.put_line (userrow.id| | ', ' | | userrow.name| | ', ' | | Userrows%rowcount);
End Loop;
End Proc_test_cursor;
—————————————————— – I'm a split-line —————————————————————

As the corresponding code for the stored procedure is shown above, you can test it in the following ways:

Enter Pl/sql, execute file-> new-> program window-> blank, copy the above paragraph code, to Pl/sql blank window, Ann F8 perform compilation.

Re-execute File-> the new-> Command window goes to the command window to execute the set serveroutput on this code, and then enter the exec corresponding stored procedure, OK.

The 5th loop requires that you create a new table field ID named Test, name, and insert a few data to test.

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.