Mysql错误1064

  导致1064错误的原因很多,需要具体问题具体分析。


  笔者是在执行存储过程中遇到的问题,其中存储过程语句:

create function CountLayer (p_node_id int) RETURNS int(11) DETERMINISTIC
BEGIN
declare p_result, p_lft, p_rgt int default 0;
if exists (select 1 from tree where node_id = p_node_id) then
begin
select lft, rgt into p_lft, p_rgt from tree where node_id=p_node_id;
select count(*) into p_result from tree where lft <= p_lft and rgt >= p_rgt;
end;
return p_result;
end if;
RETURN 0;
END

  报错的详细信息:


报错信息

  问题出在10行,但出现问题的语句为空,查询相关解决方案后,找到对应解决方案,即需要修改mysql中解释器中的命令结束符,需要用到delimiter指令,完成的指令代码如下:

delimiter //
create function CountLayer (p_node_id int) RETURNS int(11) DETERMINISTIC
BEGIN
declare p_result, p_lft, p_rgt int default 0;
if exists (select 1 from tree where node_id = p_node_id) then
begin
select lft, rgt into p_lft, p_rgt from tree where node_id=p_node_id;
select count(*) into p_result from tree where lft <= p_lft and rgt >= p_rgt;
end;
return p_result;
end if;
RETURN 0;
END
//

  即将mysql解释器的命令结束符改为//语句,这样语句就不会在line 10结束后就执行,最后能完整执行语句。

你可能感兴趣的:(Mysql错误1064)