1. if if else
delimiter $$ create procedure test_1(in in_params int) begin declare var1 int; set var1=in_params+1; if var1=0 then insert into test2(username,age) values('Ruby lin',28); end if; if in_params=0 then update test2 set age=age+1 where username='Ruby1'; else update test2 set age=age+2 where username='Ruby1'; end if; end$$ 调用:call test_1(0); 2.case指令 在很多语言中我们都会看到switch case default 可以mysql里case when then else delimiter $$ create procedure test_2(in in_params int) begin declare var1 int; set var1=in_params+1; case var1 when 0 then insert into test2(username,age) values('Ruby qiu',21); when 1 then insert into test2(username,age) values('Ruby lin',28); else insert into test2(username,age) values('Ruby qiu',21); end case; end$$ 调用call test_2(0); 3.while ... end while delimiter $$ create procedure p14() begin declare v int; set v=0; while v<5 do insert into t values(v); end while; end$$ 调用call p14(); 4.repeat ... end repeat delimiter $$ create procedure p15() begin declare v int; set v=0; repeat insert into t values(v); set v=v+1; until v>=5; end repeat; end$$ 调用:call p15(); 还有LOOP END LOOP GOTO 我不喜欢这些 所以也不建议用