码迷,mamicode.com
首页 > 数据库 > 详细

mysql 储存过程

时间:2018-01-30 21:21:01      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:iter   error   sele   blog   proc   procedure   会话   参数   一个   

创建过程

create procedure demo(in par int)//in out inout   参数名字 参数类型 
begin
set @a = 123;//会话变量 对当前会话有效,全局的变量
declare a int;//用普通变量要声明类型,只对一个作用域有用
declare a int default 5;//直接声明并赋值
set a = 123;//普通变量
if a = 123 then
end if;
if a = 12345 then
……
else
……
end if;
case a
when 1 then  select xx;
when 2 then select bb;
end case;
while a < 3000 do 
insert into demo(a);
set v = v+1;//条件一定要有自增运算,不然会一直while
end whild;
end;

Loop

loop没有条件, 所以需要用If判断 然后用leave 离开定义的loop标签
loop_label:loop
if xxx then 
leave loop_label;
end if;
end loop;
ITERATE 类型C中的continue;
create procedure error()
begin
declare exit handler for 1216//如果发生1216错误,就执行插入error_tab
insert into  error_tab (xxx);
end;

mysql 储存过程

标签:iter   error   sele   blog   proc   procedure   会话   参数   一个   

原文地址:https://www.cnblogs.com/lisq/p/8386998.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!