gpt4 book ai didi

MySQL 函数 - 错误代码 : 1415 Not allowed to return a result set from a function

转载 作者:可可西里 更新时间:2023-11-01 06:32:27 25 4
gpt4 key购买 nike

我并不想返回一个结果集,我也不知道我做错了什么。MySQL 5.5

delimiter $$

CREATE FUNCTION CheckAccount(
i_username varchar(50)
) RETURNS integer

BEGIN

DECLARE v_validUserId int;
DECLARE v_validMembership int;
DECLARE o_Status integer;

SELECT vvalidUserId = u.UserId
FROM Users u
WHERE u.Username = i_username;

IF( v_validUserId IS NULL ) THEN
SET o_Status = 2; -- Invalid username
ELSE
SET o_Status = 1; -- Good
END IF;


IF(o_Status != 2 ) THEN
SELECT v_validMembership = 1
FROM Users u
JOIN UserMemberships um on um.UserId = u.userId
JOIN Memberships m on m.MembershipId = um.MembershipId
WHERE um.MembershipExpireDateTime > CURDATE()
AND u.UserId = v_validUserId;

IF( v_validMembership IS NULL ) THEN
SET o_Status = 3; -- Invalid membership
END IF;
END IF;

RETURN o_status;

END $$
DELIMITER ;

任何帮助将不胜感激!

最佳答案

我不确定您是否可以那样分配变量,请尝试使用 INTO 语句进行选择。例如:

SELECT 
u.UserId INTO vvalidUserId
FROM
Users u
WHERE
u.Username = i_username;

关于MySQL 函数 - 错误代码 : 1415 Not allowed to return a result set from a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16177267/

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