mysql 中的判断语句(case、if)
2017-10-29 15:31
459 查看
此篇文章是通过存储过程来介绍的
1、if语句:
a、单分支 语法格式:
create procedure p1(参数)
begin
if 表达式 then 代码1;
end if;
end;
示例:
create procedure p1(a int)
begin
declare i int default 3;
if a>i then select "春天" as "季节" ;
end if;
end;
b、双分支语法格式
create procedure p1(参数)
begin
if 表达式 then 代码1;
else 代码 2
end if;
end;
示例:
create procedure p9(a int)
begin
declare i int default 3;
if a>i then select "春天" as "季节" ;
ELSE
select "夏天" as "季节" ;
end if;
end;
2、Case 语句:
语法格式:
create procedure p1(参数)
begin
case 变量 when 值 then 代码1;
when 值 then 代码2;
else 代码3;
end case;
end;
示例:
create procedure p11(a int)
begin
case a when 1 then select "夏" as "季节" ;
when 2 then select "春天" as "季节" ;
else select "秋天" as "季节" ;
end case;
end;
1、if语句:
a、单分支 语法格式:
create procedure p1(参数)
begin
if 表达式 then 代码1;
end if;
end;
示例:
create procedure p1(a int)
begin
declare i int default 3;
if a>i then select "春天" as "季节" ;
end if;
end;
b、双分支语法格式
create procedure p1(参数)
begin
if 表达式 then 代码1;
else 代码 2
end if;
end;
示例:
create procedure p9(a int)
begin
declare i int default 3;
if a>i then select "春天" as "季节" ;
ELSE
select "夏天" as "季节" ;
end if;
end;
2、Case 语句:
语法格式:
create procedure p1(参数)
begin
case 变量 when 值 then 代码1;
when 值 then 代码2;
else 代码3;
end case;
end;
示例:
create procedure p11(a int)
begin
case a when 1 then select "夏" as "季节" ;
when 2 then select "春天" as "季节" ;
else select "秋天" as "季节" ;
end case;
end;
相关文章推荐
- 【MySQL学习笔记(十)】:关于条件判断if语句
- linux边学边记---判断语句if、case、while、for
- MySQL的if,case语句使用总结
- 实现1+2+3+...+n。要求不能使用乘除法,for,while,if,else,switch,case,等关键字及条件判断语句。
- MySQL的if,case语句使用总结
- mysql中case语句和if语句的使用
- Mysql Select if 语句中实现的判断
- MYSQL ifnull 函数 、if判断 、case when、 locate函数
- mysql 里面的 IF 判断 CASE 和存储过程 MYSQ IF ELSE 判断 时间添加 DATE_ADD 总结
- MySQL中的if和case语句使用总结
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
- 求1+2+…+n, 要求不能使用乘除法、for、while、if、else、switch、case等关键字以及条件判断语句(A?B:C)。
- MySQL的if,case语句使用总结
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
- MySQL的if,case语句使用总结
- 求 1+2+3+..n不能使用乘除法、 for 、 while 、 if 、 else 、 switch 、 case 等关键字以及条件判断语句
- 《剑指offer》上的一道原题,求1+2+……+n,要求不能使用乘除法,for、while、if、else、switch、case等关键字以及条件判断语句
- 题目:求1+2+…+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字以及条件判断语句(A?B:C)
- 求1+2+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字以及条件判断语句(A? B:C)