mysql 储存过程

创建过程

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;
posted @ 2018-01-30 19:54  lisq  阅读(111)  评论(0编辑  收藏  举报