Getting SQLEXCEPTION message in MySQL procedures

后端 未结 1 1964
天涯浪人
天涯浪人 2021-02-13 17:25

How can I get error text in MySQL stored procedure when SQLEXCEPTION occurs?

I need something like this:

DECLARE EXIT HANDLER FOR SQLEXCEPTION    
BEGIN
         


        
1条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-13 17:34

    DECLARE EXIT HANDLER FOR SQLEXCEPTION    
    BEGIN
    
     GET DIAGNOSTICS CONDITION 1
        @p2 = MESSAGE_TEXT;
    
        INSERT INTO my_log (error_message) 
        SELECT @p2;
    END;
    

    0 讨论(0)
提交回复
热议问题