gpt4 book ai didi

mysql - #1064 - 你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解要使用的正确语法

转载 作者:行者123 更新时间:2023-11-29 18:24:09 25 4
gpt4 key购买 nike

尝试在数据库 weeki 上运行 SQL 查询时,我不断收到此错误。我到处寻找解决方案,但我只是运气不好。

#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 5

我正在尝试将其添加到我的数据库中

CREATE FUNCTION weeki.CreateGroup(GroupName VARCHAR(50), GroupIcon TEXT, GroupDescription VARCHAR(130), GroupCreator INT)
RETURNS int(11)
DETERMINISTIC
BEGIN
DECLARE groupID INT;
INSERT INTO groups (name, icon, description) VALUES (GroupName, GroupIcon, GroupDescription);
SET groupID = LAST_INSERT_ID();
INSERT INTO group_members VALUES (groupID, GroupCreator);
RETURN groupID;
END;

CREATE FUNCTION weeki.AddMessage(r VARCHAR(255), s INT, t INT, m VARCHAR(255), creation DATETIME)
RETURNS int(11)
DETERMINISTIC
BEGIN
DECLARE lastID INT;
DECLARE receiver INT;
SELECT id INTO receiver from users WHERE username=r;
INSERT INTO messages (receiver_id, sender_id, msg_type, message, created_At) values(receiver, s, t, m, creation);
SET lastID = LAST_INSERT_ID();
INSERT INTO messages_receipt (message_id, user_id, is_delivered) VALUES (lastID, receiver, 0);
RETURN lastID;
END;

CREATE FUNCTION weeki.AddGroupMessage(gid INT, s INT, t INT, m VARCHAR(255), creation DATETIME)
RETURNS int(11)
DETERMINISTIC
BEGIN
DECLARE lastID INT; DECLARE rowCount INT;
SELECT COUNT(*) INTO rowCount FROM group_members WHERE user_id = s AND group_id = gid;
IF rowCount = 1 THEN
INSERT INTO group_messages (group_id, user_id, msg_type, message, created_at) VALUES (gid, s, t, m, creation);
SET lastID = LAST_INSERT_ID();
INSERT INTO group_receipt (message_id, user_id, is_delivered) SELECT gm.message_id, gmembers.user_id, 0 FROM
group_messages gm LEFT JOIN group_members gmembers ON gmembers.group_id = gm.group_id WHERE gm.group_id = gid AND gm.message_id = lastID AND NOT gmembers.user_id = s;
RETURN lastID;
ELSE
return 0;
END IF;
END;

CREATE DEFINER = 'abdal'@'localhost'
FUNCTION weeki.AddGroupMember(GroupID INT, MemberName VARCHAR(255), Username INT)
RETURNS int(11)
BEGIN
INSERT INTO group_members VALUES (GroupID, MemberName);
RETURN 1;
END;

有人对如何解决这个问题有任何想法吗?我感谢所有的答案。

最佳答案

@GordonLinoff 说了什么!

DELIMITER ##

CREATE FUNCTION weeki.CreateGroup(GroupName VARCHAR(50), GroupIcon TEXT, GroupDescription VARCHAR(130), GroupCreator INT)
RETURNS int(11)
DETERMINISTIC
BEGIN
DECLARE groupID INT;
INSERT INTO groups (name, icon, description) VALUES (GroupName, GroupIcon, GroupDescription);
SET groupID = LAST_INSERT_ID();
INSERT INTO group_members VALUES (groupID, GroupCreator);
RETURN groupID;
END##

CREATE FUNCTION weeki.AddMessage(r VARCHAR(255), s INT, t INT, m VARCHAR(255), creation DATETIME)
RETURNS int(11)
DETERMINISTIC
BEGIN
DECLARE lastID INT;
DECLARE receiver INT;
SELECT id INTO receiver from users WHERE username=r;
INSERT INTO messages (receiver_id, sender_id, msg_type, message, created_At) values(receiver, s, t, m, creation);
SET lastID = LAST_INSERT_ID();
INSERT INTO messages_receipt (message_id, user_id, is_delivered) VALUES (lastID, receiver, 0);
RETURN lastID;
END##

CREATE FUNCTION weeki.AddGroupMessage(gid INT, s INT, t INT, m VARCHAR(255), creation DATETIME)
RETURNS int(11)
DETERMINISTIC
BEGIN
DECLARE lastID INT; DECLARE rowCount INT;
SELECT COUNT(*) INTO rowCount FROM group_members WHERE user_id = s AND group_id = gid;
IF rowCount = 1 THEN
INSERT INTO group_messages (group_id, user_id, msg_type, message, created_at) VALUES (gid, s, t, m, creation);
SET lastID = LAST_INSERT_ID();
INSERT INTO group_receipt (message_id, user_id, is_delivered) SELECT gm.message_id, gmembers.user_id, 0 FROM
group_messages gm LEFT JOIN group_members gmembers ON gmembers.group_id = gm.group_id WHERE gm.group_id = gid AND gm.message_id = lastID AND NOT gmembers.user_id = s;
RETURN lastID;
ELSE
return 0;
END IF;
END##

CREATE DEFINER = 'abdal'@'localhost'
FUNCTION weeki.AddGroupMember(GroupID INT, MemberName VARCHAR(255), Username INT)
RETURNS int(11)
BEGIN
INSERT INTO group_members VALUES (GroupID, MemberName);
RETURN 1;
END##

DELIMITER ;

关于mysql - #1064 - 你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解要使用的正确语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46329338/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com