如果我输入的值不同,它会起作用。它给我留下了消息文本的价值"那本电子书不存在"
如果我输入数据库中的确切值,它只执行但不返回任何值。为什么呢?
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;
答案 0 :(得分:0)
因为那时程序的其他情况将在你没有设置MESSAGE_TEXT
的地方执行。试试这个:
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;