gpt4 book ai didi

mysql - 如何发现MySQL存储过程的问题?

转载 作者:行者123 更新时间:2023-11-29 23:46:35 25 4
gpt4 key购买 nike

我有以下存储过程:

DELIMITER $$

CREATE DEFINER=`195414_py82740`@`%` PROCEDURE `getUserMail`(inUserId INT)
BEGIN

DECLARE done INT default 0;
DECLARE tmpMailId INT default -1;
DECLARE tmpFromUserId INT default -1;

DECLARE cursor1 cursor for select id from mail WHERE toUserId=inUserId OR fromUserId=inUserId ORDER BY sentDate desc;

DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;

DROP TEMPORARY TABLE IF EXISTS temp_userMail;
CREATE TEMPORARY TABLE temp_userMail LIKE mail;

OPEN cursor1;

REPEAT

FETCH cursor1 INTO tmpMailId;

SET tmpFromUserId = IF ((SELECT fromUserId FROM mail WHERE id=tmpMailId)=inUserId, (SELECT toUserId FROM mail WHERE id=tmpMailId), (SELECT fromUserId FROM mail WHERE id=tmpMailId));

IF EXISTS(SELECT id FROM temp_userMail WHERE fromUserId=tmpFromUserId || toUserId=tmpFromUserId) THEN
SET tmpMailId = 0;
ELSE
INSERT INTO temp_userMail
(`id`,
`fromUserId`,
`toUserId`,
`sentDate`,
`readDate`,
`message`,
`fromUserNickName`,
`toUserNickName`,
`subject`,
`fromUserDeleted`,
`toUserDeleted`)
SELECT
(m1.id,
m1.fromUserId,
m1.toUserId,
m1.sentDate,
m1.readDate,
m1.message,
m1.fromUserNickName,
m1.toUserNickName,
m1.subject,
m1.fromUserDeleted,
m1.toUserDeleted)
FROM mail m1
WHERE m1.id=tmpMailId;

END IF;

UNTIL(done = 1)

END REPEAT;
CLOSE cursor1;

SELECT * FROM temp_userMail ORDER BY sentDate DESC;

END

SP 已成功保存,但运行时出现神秘异常

Error Code: 1241: Operand should contain 1 column(s).

我知道错误的含义,但没有行号,所以我不知道在哪里查找问题?

最佳答案

从 SELECT 子查询中删除括号

不要使用

 SELECT (id, ... m1.toUserDeleted) ...

使用

 SELECT id, ... m1.toUserDeleted ...

关于mysql - 如何发现MySQL存储过程的问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25900650/

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