创建存储过程的完整命令:
CREATE PROCEDURE pro1()
begin
declare b int default 0;
end;
mysql中运行存储过程创建语句错误结果:
root@db1>CREATE PROCEDUREpro1()
-> begin
-> declare b int default 0;
ERROR 1064 (42000): You havean error in your SQL syntax; check the manual that corresponds to your MySQLserver version for the right syntax to use near '' at line 3
root@db1>end;
mysql 默认把分号做为命令执行的结束标识符号。在创建存储过程命令中当遇见declare b int default 0;语句中的分号时,mysql解释器立即执行declare b int default 0;及其之前的语句,所以报语法错误。
我们可以使用delimiter命令来改变mysql 命令执行结束符。
root@db1>delimiter $
root@db1>CREATE PROCEDUREpro1()
-> begin
-> declare b int default 0;
-> end;
-> $
Query OK, 0 rows affected(0.00 sec)
root@db1>