#1064 - You have an error in your SQL syntax; version for the right syntax to use near '' at line

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 33

初次写MySQL的存储过程的时候,以为和其他数据库的存储过程一样,先写完了sql,再放入存储过程就可以了.但是mysql的时候,就碰壁了,如一下的sql是没有问题的

create procedure proc_name
begin
    select * from table_name;
end

 奈何我的sql里有嵌套的如

create procedure proc_name
begin
    update table_name a,(
        select b.id,b.name from b -- 这里有复杂的嵌套,只是简单写
    ) b
    set a.isOvertime=b.isOvertime 
    where a.id=b.id;
end

这样就会报错了,网上找了好久终于找到解决方案

DROP PROCEDURE IF EXISTS proc_name;
DELIMITER //
create procedure proc_name
begin
    update table_name a,(
        select b.id,b.name from b -- 这里有复杂的嵌套,只是简单写
    ) b
    set a.isOvertime=b.isOvertime 
    where a.id=b.id;
end //
DELIMITER ;

MySQL语句默认分隔符为分号; 我们先就是定义新的分隔符//, 然后存储过程内的分号;就不会影响,存储过程结束再恢复分隔符为;

MYSQL存储过程

发布了64 篇原创文章 · 获赞 34 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/svygh123/article/details/103208853
今日推荐