Databases| SQL| MySQL| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Mysql Loop in Procedure 
 

Loop in Procedure is a simple loop construct that enables an repeated execution of the statement list, which consists of one or more statements.

 

Mysql Loop in Procedure

                         

Loop in Procedure is a simple loop construct that enables an repeated execution of the statement list, which consists of one or more statements.Each loop is terminated by a semicolon(;) or statement delimiter. The statement within a loop are repeated untill your loop is exited; this is normally terminated by a LEAVE statement .

Understand with Example

The Tutorial helps you to understand an example from 'Mysql Loop in Procedure'.To grasp this example we create a procedure 'myloop'.The Procedure starts with the BEGIN-END pair statement that declare a variable counter and set to default value of 0.The statement within a loop are repeated untill the counter reached to 50.

The Loop will be terminated once the counter is assigned to 50.This is normally accompanied with LEAVE statement.

 

 

Query to Create Procedure named myloop:-

mysql> CREATE PROCEDURE myloop()
    ->        BEGIN
    ->        DECLARE counter INT DEFAULT 0;
    ->        simple_loop: LOOP
    ->          SET counter=counter+10;
    ->          select counter;
    ->          IF counter=50 THEN
    ->             LEAVE simple_loop;
    ->          END IF;
    ->        END LOOP simple_loop;
    -> ENDGG
Query OK, 0 rows affected (0.00 sec)

Output showing the use if Loop in procedure:-

mysql> call myloop();
    -> GG
+---------+
| counter |
+---------+
|      10 |
+---------+
1 row in set (0.00 sec)
+---------+
| counter |
+---------+
|      20 |
+---------+
1 row in set (0.05 sec)
+---------+
| counter |
+---------+
|      30 |
+---------+
1 row in set (0.11 sec)
+---------+
| counter |
+---------+
|      40 |
+---------+
1 row in set (0.19 sec)
+---------+
| counter |
+---------+
|      50 |
+---------+
1 row in set (0.25 sec)
Query OK, 0 rows affected (0.31 sec)

                         

» View all related tutorials
Related Tags: sql mysql c string oop com function fun io sed char padding length oo character if unc cte add nat

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.