我试图找出如何在MySQL(5.7)中抛出带有格式化错误消息的错误。
// SOME PROCEDURE
begin
declare something INT;
start transaction;
call getsomething(something); // sets something to data
if something is NULL then
rollback;
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Something %d not found!', MYSQL_ERRNO = 1001;
end if;
commit;
end
我如何使用"某些东西"创建错误消息时变量?
答案 0 :(得分:1)
答案 1 :(得分:1)
// SOME PROCEDURE
begin
declare something INT;
declare error_msg VARCHAR(255);
start transaction;
call getsomething(something); // sets something to data
if something is NULL then
rollback;
set error_msg = CONCAT('Something not found!', something);
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = error_msg, MYSQL_ERRNO = 1001;
end if;
commit;
end
关注@Samis评论并使用CONCAT重试 - 以上工作。