gpt4 book ai didi

MySQL存储过程没有返回值

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

如果我输入不同的值,它就会起作用。它返回了消息文本“该电子书不存在”的值

如果我输入数据库中的确切值,它只会执行但不会返回任何值。为什么?

CREATE PROCEDURE SPBus ( 
IN BUS VARCHAR (20)
)
BEGIN

START TRANSACTION;
IF NOT EXISTS (SELECT * FROM Ebook WHERE TituloEbook LIKE CONCAT('%',BUS,'%' )) THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT= 'That ebook doesnt exists';
ELSE
SELECT * FROM Ebook WHERE TituloEbook LIKE CONCAT('%',BUS, '%');
END IF;
COMMIT;
END;

最佳答案

因为当您没有设置 MESSAGE_TEXT 时,将执行该过程的 else 情况。试试这个:

CREATE PROCEDURE SPBus ( 
IN BUS VARCHAR (20)
)
BEGIN

START TRANSACTION;
IF NOT EXISTS (SELECT * FROM Ebook WHERE TituloEbook LIKE CONCAT('%',BUS,'%' )) THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT= 'That ebook doesnt exists';
ELSE
SELECT * FROM Ebook WHERE TituloEbook LIKE CONCAT('%',BUS, '%');
SET MESSAGE_TEXT = 'That ebook exists';
END IF;
COMMIT;
END;

关于MySQL存储过程没有返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27209674/

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