MySQL Loop usage

Source: Internet
Author: User

While for example

DROP PROCEDURE IF EXISTS Zy.test_pro;
DELIMITER $$
CREATE PROCEDURE Zy.test_pro (in ID INT)
BEGIN
DECLARE num INT;
SET Num=1;
While Num <=id do
INSERT into Zy.test VALUES (num,concat (' Test ', num));
SET num = num +1;
END while;
END;


Repate

Delimiter//drop procedure if exists looppc;create procedure LOOPPC () Begin DECLARE I int;set i = 1;        Repeat INSERT into User_profile_company (UID) values (i+1);  Set i = i + 1; Until I >= end repeat;end//----calls call LOOPPC ()

Loop

Delimiter $ $drop Procedure if exists lopp;create procedure Lopp () BEGIN declare I int; set i = 1;lp1:loop//           LP1 the loop body name loop as the keyword INSERT into user_profile (UID) values (i);        Set i = i+1;              If i > then leave LP1; Leave the loop body End if;              End LOOP; Ending Loop End $$

MySQL Loop usage

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.