Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learn SQL using MySQL in One Day and Learn It Well

You're reading from  Learn SQL using MySQL in One Day and Learn It Well

Product type Book
Published in Apr 2024
Publisher Packt
ISBN-13 9781836205678
Pages 121 pages
Edition 1st Edition
Languages
Author (1):
Jamie Chan Jamie Chan
Profile icon Jamie Chan

LOOP statement

 

Last but not least, let’s move on to the LOOP statement. This statement is very similar to the WHILE and REPEAT statements, except that it does not come with a condition to exit the loop.

 

Instead, we use the ITERATE or LEAVE keywords to exit it.

 

The syntax of a LOOP statement is:

 

[name of loop statement :] LOOP

-- some tasks

END LOOP;

 

Let’s look at a few examples.

 

Example 1

 

DELIMITER $$

CREATE FUNCTION loop_demo_A(x INT, y INT) RETURNS VARCHAR(255) DETERMINISTIC

BEGIN

DECLARE z VARCHAR(255);

SET z = '';

 

simple_loop: LOOP       

      SET x = x + 1;

      IF x > y THEN

            LEAVE simple_loop;

      END IF;

      SET z = concat(z,...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}