There are two ways to implement a conditional loop
A, for variable in start value ... Ends the value loop end loop;
Two, while conditions loop end loop;
How loop is used:
One, X: = 100;
LOOP
X: = x + 10;
IF X > 1000 THEN
EXIT;
End IF LOOP;
Y: = X;
Two, X: = 100;
LOOP
X: = x + 10;
EXIT when X > 1000;
X: = x + 10;
End LOOP;
Y: = X;
There is also a use of Goto, which will be used in the subsequent process 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 1 to 100 of the and
The value of T is the and
*/
I number (10);
T number (10);
Begin
/*
I: = 1;
T: = 0;
--using While+loop to realize
/*begin
While I <= loop
T: = t + i;
I: = i + 1;
End Loop;
End
*/
I: = 1;
T: = 0;
--For implementation
Begin
For I in 1. Loop
T: = t + i;
End Loop;
End
End Count_number;
For loop:
[Pl/sql] replaces cursor with a for loop
Http://www.itwenzhai.com/data/2006/0523/article_9377.htm
Http://blog.csdn.net/heyday/archive/2005/07/27/435804.aspx
CURSOR for Loop
For EMPLOYEE_REC in C1---employee_rec directly, without prior definition
LOOP
Total_val: = Total_val + employee_rec.monthly_income;
End LOOP;
When using the cursor for loop, I do not have to manually open cursor close cursor
Application:
Begin
For Emm in (SELECT ro_site, Ns_site, Product_Line, Wh_type
From Eis_hq_invhl_mail_data
WHERE report_type = ' Detailed ')
LOOP
Dbms_output.put_line (Emm.product_line);
Eis_hq_invhl_pkg.make_mail_detailed_data
(P_ro_site => Emm.ro_site,
P_ns_site => Emm.ns_site,
P_product_line => Emm.product_line,
P_wh_type => Emm.wh_type,
P_current_day => to_date (' 2005-11-07 ', ' yyyy-mm-dd '));
End LOOP;
End
Stored Procedures DIY2----cursors and loops
Http://blog.csdn.net/brave1/archive/2005/06/08/390160.aspx
While Loop:
while (I <= ceil (LENGTH (p_clob_data)/4000))
LOOP
V_clob_data: = TRIM (SUBSTR (P_clob_data,
I * 4000,
4000));
Dbms_output.put_line (SUBSTR (V_clob_data,
0,
255));
I: = i + 1;
End LOOP;