SQL:
CREATE FUNCTION delete_user (uId INT) RETURNS BOOLEAN
BEGIN
IF uID >= 0 THEN
START TRANSACTION;
DELETE FROM Folder WHERE u_id = uId;
DELETE FROM `User` WHERE id = uId;
RETURN 1;
END IF;
RETURN 0;
END;
错误:
#1064 - 您的SQL语法出错;检查与MySQL服务器版本对应的手册,以便在第4行的''附近使用正确的语法
语法错误在哪里?
答案 0 :(得分:1)
您需要在函数周围添加分隔符
delimiter |
CREATE FUNCTION delete_usr (uId INT) RETURNS BOOLEAN
BEGIN
IF uID >= 0 THEN
DELETE FROM Folder WHERE u_id = uId;
DELETE FROM `User` WHERE id = uId;
RETURN 1;
END IF;
RETURN 0;
END
|
delimiter ;
默认分隔符为;
。但是如果你想创建过程/函数,数据库引擎会认为你的语句在第一个;
结束。这将导致不完整的陈述。您可以定义另一个分隔符,然后使用它来标记语句的结尾。