MySQL Stream control statement (loop, REPEAT, while)

Source: Internet
Author: User

1.loop
Grammar:
[ begin_label :] LOOP    END LOOP [ end_label ]  statement_list 
 example: 
CREATE PROCEDURE doiterate (P1 INT) BEGIN label1:loop SET p1 = p1 + 1; IF P1 < iterate label1;//iterate  can appear only Within loop ,  repeat , And while  statements. iterate  means  " start the loop again. " END IF; LEAVE label1;//leave  can be used Within begin ... END  or Loop constructs (loop ,  repeat ,  while ). END LOOP Label1; SET @x = p1; END;
2.repeat
Syntax
[  Begin_label  :] REPEAT   statement_list   UNTIL   search_condition   END REPEAT [  End_ Label  ] 

Example:
mysql>   delimiter//  mysql> Strong class= "Userinput" >  CREATE PROCEDURE dorepeat (P1 INT)  , <    Code>begin  ,   SET @x = 0;   -  REPEAT  ,   SET @x = @x + 1;      -  UNTIL @x > P1 END REPEAT;     END  - //  Query OK, 0 rows Affected (0.00 sec) mysql>   call Dorepeat (+)/// Strong>query OK, 0 rows Affected (0.00 sec) mysql>   SELECT @x//  +----- -+| @x |+------+| 1001 |+------+1 Row in Set (0.00 sec) 

3.while
Syntax
 begin_label   [ search_condition do    ENDwhile end_label [] statement_list 
Example:
CREATE PROCEDURE dowhile () BEGIN  DECLARE v1 INT DEFAULT 5;  While v1 > 0 do    ...    SET v1 = v1-1;  END while; END;

4.label Markup Syntax
[ begin_label :] BEGIN    [ statement_list  end_label ]end begin_label []: Loop     end_label END Loop [] [ statement_list   begin_label :] REPEAT     statement_list  END REPEAT [ begin_label  ] [ end_label  search_condition   search_condition  do    END while [ end_label ]  statement_list 




MySQL Stream control statement (loop, REPEAT, while)

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.