mysql的存储过程的代码中不仅可以执行单条sql语句,也可以执行多条语句和条件语句。
在MySQL的存储过程中执行多条sql语句的语法是:
create procedure proc_name([parameter [, …]])
begin
sql语句
…
end
MySQL存储过程中的条件语句:
if-then-else,语法如下:
if condition then
statement1;
else
statement2;
end if;
MySQL存储过程中的case语句,语法如下:
case variable
when value1 then statement1;
when value2 then statement2;
…
else statement;
end case;
MySQL存储过程中的循环语句:
while,语法如下:
while condition do
statements;
end while;
repeat语句,语法如下:
repeat
statement;
until condition
end while;
loop语句,语法如下:
loop_lebel:phpdo
statements;
if condition then
leave loop_label; //离开循环
end if;
end loop;






其实还有定义变量