An example analysis of Oracle stored procedure cycle syntax _oracle

Source: Internet
Author: User

The example in this article describes the Oracle stored procedure looping syntax. Share to everyone for your reference, specific as follows:

1. Simple cycle

Grammar

loop
  statements;
End Loop;

Example:

Counter: = 0;
Loop
  Counter: = counter + 1;
  Exit when counter = 5;
End Loop;

Note: The exit statement ends the loop immediately, and the exit when statement stops the loop when the specified condition appears (you can appear anywhere in the Loop code)

2, while loop

Grammar

While condition loop
  statements end
Loop;

Example:

Counter: = 0;
While counter < 6 loop
  Counter: = counter + 1;
End Loop;

3, for Loop

Grammar

For loop_variable in [reverse] lower_bound ... Upper_bounder Loop
  statements end
Loop;

Example:

For Count2 in 1..5 loop
  dbms_output. Put_Line (count2);
End Loop;

I hope this article will help you with your Oracle database program design.

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.