Mysql:leave Statement

Source: Internet
Author: User
Tags mysql tutorial

https://www.techonthenet.com/mysql/loops/leave.php

This MySQL tutorial explains how to use the LEAVE statement in MySQL with syntax and examples.

Description

In MySQL, the LEAVE statement are used when you want to exit a block of code identified by a label_name, such as a Loop statement, while statement, or REPEAT statement.

Syntax

The syntax for the LEAVE statement in MySQL is:

LEAVE label_name;
Parameters or Arguments
Label_name
the name of the block of code (Ie:loop, while, REPEAT) to terminate.
Note
    • The LEAVE statement to terminate a block of code, such as a LOOP statement, while statement, or REPEAT statement T Hat is identified by a label_name.
Example

Let's look at a example that shows how to use the LEAVE statement in MySQL:

DELIMITER //CREATE FUNCTION CalcIncome ( starting_value INT )RETURNS INTBEGIN   DECLARE income INT;   SET income = 0;   label1: LOOP     SET income = income + starting_value;     IF income < 3000 THEN       ITERATE label1;     END IF;     LEAVE label1;   END LOOP label1;   RETURN income;END; //DELIMITER ;

In this LEAVE example, we have created a loop called Label1 using the loop statement.

The iterate statement would cause the loop to repeat while income was less than 3000. Once income is greater than or equal to, the LEAVE statement would terminate the LOOP.

Mysql:leave Statement

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.