简而言之,类似于封装函数
特点
基本语法
create peocedure p1()
begin
select coun(*) from studuent;
end;
call p1();
设置完别忘了把delimiter改回来
变量
系统变量
用户自定义变量
set @myname = 'its';
set @myage := 10;
局部变量
if
参数(IN,OUT,INOUT)
case
create procedure p1(in month int)
begin
declare result varchar(10);
case
when month>=1 and month <=3 then
set result := '一';
when month>=4 and month <=6 then
set result := '二';
when month>=7 and month <=9 then
set result := '三';
when month>=10 and month <=12 then
set result := '四';
else
set result := '非法';
end case;
select concat('您输入的参数为', month, '季度为',result);
end;
循环语句
while
repeat![](https://i-blog.csdnimg.cn/blog_migrate/e046c9bcf00191d53dc1a5b532c12f13.png)
loop![](https://i-blog.csdnimg.cn/blog_migrate/724ab3d9ce6e36b8d14e9ffd28f96ae0.png)
游标
但是这个有问题,while true是一直循环
可以使用Handler处理
条件处理程序Handler
刚才的程序多声明一句handler语句就可以成功退出循环
存储函数![](https://i-blog.csdnimg.cn/blog_migrate/3d789fdc9818bb256d68c28037b4a44c.png)
存储函数不如存储过程,存储函数必须有返回值