【mysql-变量和流程控制语句】教程文章相关的互联网学习教程文章

mysql之流程控制【代码】

目录分支结构 循环结构 分支结构:1.if condition then [statement] elseif condition then [statement] else [statement] end if实例:求两个数中的最大值,如果两个数据相等,则返回0,不相等,则返回最大值  delimiter // create function test_if(a int,b int) returns int BEGIN DECLARE max int DEFAULT 0;  -- 下面为分支结构if a > b then set max = a;ELSEIF a<b then set max = b;ELSEset max = 0;end if;retur...

MySQL之流程控制

流程控制 一、if条件语句 第一种 if: """ if 条件 then 语句; end if; """ 第二种 if elseif """ if 条件 then 语句1; elseif 条件 then 语句2; else 语句3; end if; """ 案例:编写过程 实现 输入一个整数type 范围 1 - 2 输出 type=1 or type=2 or type=other; delimiter // create procedure showType(in type int,out result char(20)) begin if type = 1 then set result = "type = 1"; elseif type = 2 then set result = ...

Mysql(10)_存储过程与流程控制【代码】【图】

一 存储过程与if语句-- ---------------------------- -- Procedure structure for `proc_adder` -- ---------------------------- DROP PROCEDURE IF EXISTS `proc_adder`; DELIMITER $$ CREATE DEFINER=`root`@`localhost` PROCEDURE `proc_adder`(IN a int, IN b int, OUT sum int) BEGIN#Routine body goes here...DECLARE c int;if a is null then set a = 0; end if;if b is null then set b = 0;end if;set sum = a + b; ...