如果出现SQLEXCEPTION,如何在MySQL存储过程中获取错误文本?
我需要这样的东西:
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
INSERT INTO my_log (error_message)
VALUES (SQLEXCEPTION.message);
END;
答案 0 :(得分:4)
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
GET DIAGNOSTICS CONDITION 1
@p2 = MESSAGE_TEXT;
INSERT INTO my_log (error_message)
SELECT @p2;
END;