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 is 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

  • You use the LEAVE statement to terminate a block of code, such as a LOOP statement, WHILE statement, or REPEAT statement that is identified by a label_name.

Example

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

DELIMITER //

CREATE FUNCTION CalcIncome ( starting_value INT )
RETURNS INT BEGIN 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 is less than 3000. Once income is greater than or equal to 3000, the LEAVE statement would terminate the LOOP.

MySQL: LEAVE Statement的更多相关文章

  1. MySql用statement实现DDL,DML,DQL的操作Demo

    Demo1 Connection connection=null; Statement stmt=null; int result=-1; try { Class.forName("com. ...

  2. MyBatis项目快速搭建及MySQL一个Statement支持多条命令参数

    一.简述 本文以笔记的形式,记录一个基本Mybatis项目的使用,方便后期项目使用到相关配置时直接复制使用. 二.项目结构 pom.xml中的依赖 <!-- https://mvnreposit ...

  3. MySQL 5.7 Replication 相关新功能说明

    背景: MySQL5.7在主从复制上面相对之前版本多了一些新特性,包括多源复制.基于组提交的并行复制.在线修改Replication Filter.GTID增强.半同步复制增强等.因为都是和复制相关, ...

  4. java分享第十七天-03(封装操作mysql类)

     JAVA操作mysql所需jar包:mysql-connector-java.jar代码: import java.sql.*; import java.util.ArrayList; import ...

  5. Mybatis拦截器 mysql load data local 内存流处理

    Mybatis 拦截器不做解释了,用过的基本都知道,这里用load data local主要是应对大批量数据的处理,提高性能,也支持事务回滚,且不影响其他的DML操作,当然这个操作不要涉及到当前所lo ...

  6. LeetCode 177 Nth-Highest Salary mysql,取第n条数据,limit子句 难度:1

    https://leetcode.com/problems/nth-highest-salary/ ATTENTION:limit 子句只能接受int常量,不能接受运算式 CREATE FUNCTIO ...

  7. Type mismatch: cannot convert from java.sql.PreparedStatement to com.mysql.jdbc.PreparedStatement

    Connection.prepareStatement()函数出错,提示: Type mismatch: cannot convert from java.sql.PreparedStatement ...

  8. Raising Error Conditions with MySQL SIGNAL / RESIGNAL Statements

    http://www.mysqltutorial.org/mysql-signal-resignal/ Summary: in this tutorial, you will learn how to ...

  9. 再次熟悉jdbc连接mysql

    闲来无事想探究一下jdbc 1.首先准备工作.我们要下载jdbc驱动包mysql-connector-java-5.1.7-bin.jar.其他的暂时先不用,这个包的下载地址:http://pan.b ...

随机推荐

  1. Java-接口练习

    编写2个接口:InterfaceA和InterfaceB:在接口InterfaceA中有个方法voidprintCapitalLetter():在接口InterfaceB中有个方法void print ...

  2. WebApi系列~通过HttpClient来调用Web Api接口

    回到目录 HttpClient是一个被封装好的类,主要用于Http的通讯,它在.net,java,oc中都有被实现,当然,我只会.net,所以,只讲.net中的HttpClient去调用Web Api ...

  3. Node.js入门:Node.js&NPM的安装与配置

    Node.js安装与配置      Node.js已经诞生两年有余,由于一直处于快速开发中,过去的一些安装配置介绍多数针对0.4.x版本而言的,并非适合最新的0.6.x的版本情况了,对此,我们将在0. ...

  4. java的五种数据类型解析

    不知道大家对java的简单数据类型是否了解,下面针对Java的五种类型简单数据类型表示数字和字符,进行详细的讲解和分析. 一.简单数据类型初始化 在Java语言中,简单数据类型作为类的成员变量声明时自 ...

  5. C 中读取键盘码

    键盘码在底层开发中经常用到,有时候我们会忘记它们,就要急急忙忙的去找 键-码 对照表查看,其实程序可以自己打印出 键-码 对应值 #include <stdio.h> #include & ...

  6. Multiton & Singleton

    From J2EE Bloger http://j2eeblogger.blogspot.com/2007/10/singleton-vs-multiton-synchronization.html ...

  7. [转] SSH原理与运用(2):远程操作与端口转发

    英文:阮一峰 链接:http://www.ruanyifeng.com/blog/2011/12/ssh_port_forwarding.html 接着前一次的文章,继续介绍SSH的用法. (Imag ...

  8. CSS实现点击事件及实践

    实现原理利用:target,把a标签自身的href以及id设置成一样的. 案例1:实现元素的切换 HTML: <div id="box"> <a href=&qu ...

  9. javascript类型系统——undefined和null

    × 目录 [1]原因 [2]undefined [3]null 前面的话 一般的程序语言,表示空的只有null,但javascript的设计者Brendan Eich却设计了一个undefined,这 ...

  10. 浅谈A/B测试里常见的辛普森悖论,企业决策者必看

    A/B测试背后有着高深的统计学知识,今天我们就来讲讲常见的辛普森悖论. 辛普森悖论 (Simpson's Paradox) 是英国统计学家 E.H.辛普森 (E.H.Simpson) 于1951年提出 ...