作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尝试在数据库 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/
现在我正在尝试实现 flash programming specification对于 PIC32MX。我正在使用 PIC32MX512L 和 PIC32MX512H。 PIC32MX512L最终必须
我是一名优秀的程序员,十分优秀!