Learning of Oracle conditional statements and cyclic statements (1)

Source: Internet
Author: User

Conditional loops can be implemented in two ways.
1. For variable in start value... end value loop end loop;
2. While condition loop end loop;

Loop usage:
I. X: = 100;
Loop
X: = x + 10;
If X> 1000 then
Exit;
End if end loop;
Y: = X;
Ii. X: = 100;
Loop
X: = x + 10;
Exit when x> 1000;
X: = x + 10;
End loop;
Y: = X;

There is also a goto usage, which will be available in later processes to generate error logs.

The following is a very simple process to familiarize yourself with loops!

Create or replace procedure count_number is
/*
Function Description: calculates the sum of 1 to 100.
T value is sum
*/

I number (10 );
T number (10 );

Begin
/*
I: = 1;
T: = 0;
-- Implement with while + Loop
/* Begin
While I <= 100 Loop
T: = T + I;
I: = I + 1;
End loop;
End;
*/
I: = 1;
T: = 0;
-- Implement with

Begin
For I in 1 .. 100 Loop
T: = T + I;

End loop;
End;

End count_number;

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.