循环
WHILE……DO……END WHILE
REPEAT……UNTIL END REPEAT
LOOP……END LOOP
GOTO。
mysql> create procedure pro10()
存过 游标 代码编写中有不少规则,比如游标声明必须在变量之后,在handler之前
delimiter //
create procedure test02()
begin
declare v_id int;
-- 遍历数据结束标志 很重要
DECLARE done INT DEFAULT FALSE;
declare cur cursor for select id from crm.t1;
-- 将结束标志绑定到游标 很重要
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
open cur;
while !done do
fetch cur into v_id;
update crm.t1 set col_1 = v_id*2 where id = v_id;
end while;
commit;
close cur;
end
//
--调试存过,相当于oracle的dbms_output.put_line(); 直接select
create procedure test03()
begin
declare v_id int;
select id into v_id from t1 where id= 1;
select v_id;
end;
//
测试输出参数的存过
create procedure test04(out total int)
begin
select count(*) into total from t1;
end;
测试 call test04(@a);
create procedure test5(in v_id int , out v_remark int)
begin
select col_1 into v_remark from t1 where id = v_id;
end;