For and while loops in Oracle

Source: Internet
Author: User

Instance:

Begin
For I in 51..500 loop
Delete from Test T where T.date=to_date (' 2016-07-01 ', ' yyyy-mm-dd ') and t.name like ('% ' | | | i);-------Oracle Use | | As a connector

Update Test T set t.code= (' text-0000-2-' | | Lpad (1,3, ' 0 ')), T.name=replace (T.name, ' 3001 ', ' 0000 ') where To_char (t.date, ' yyyymm ') = ' 201606 ';---------lpad complement function, Replace replacement function, To_char date conversion function
Commit
End Loop;
End

There are two ways to implement conditional loops
One, for variable in start value ... End value loop end loop;
Second, while condition Loop end loop;

How loops are used:
One, X: = 100;
LOOP
X: = x + 10;
IF X >
EXIT;
End IF End 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 goto that will be used later in the process to generate the error log.

Here is a very simple process to familiarize yourself with the loop!

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 achieve
/*begin
While I <= loop
T: = t + i;
I: = i + 1;
End Loop;
End
*/
I: = 1;
T: = 0;
--With for

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

End Loop;
End

End Count_number;

For Loop:
[PL/SQL] replacing the 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, do not use my manual 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 procedure 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;

For and while loops in Oracle

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.