Iterative (loop) control statement syntax in Oracle ____oracle

Source: Internet
Author: User

1. Simple cycle
Loop
sequence of statements;
End Loop;
Cases:
Declare
a number:=100;
Begin
Loop
a:=a+25;
Exit when a=250;
End Loop;
Dbms_output.put_line (To_char (a));--note here with To_char ()
End

2.For Loop
For counter in [Reverse]lowerbound...upperbound
Loop
sequence of statements;
End Loop;

Counter is a counter variable, which is not declared here, and this variable can only be read in the loop body and cannot be assigned a value. If i++ is wrong.
Lowbound is the lower bound.
Upperbound is an upper bound, by default, iteration from the lower bound to the upper bound and, if the keyword reverse is used, the iteration from the upper bound to the lower bound
Cases:
Begin
For I in 1..2--if reversed, use the reverse keyword to
Loop
Update order_master set ostatus= ' P ' where odate<sysdate;
End Loop;
End

3.While Loop
while <condition>
Loop
    sequence of statements;
End Loop;
Example:
Declare
   i number:=0;
   J number:=0;  
Begin
   while i<=100 loop
          J:=j+i;
         i:=i+2;
   end Loop;
end; 

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.