Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting SQLEXCEPTION message in MySQL procedures

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

I need something like this:

DECLARE EXIT HANDLER FOR SQLEXCEPTION    
BEGIN
    INSERT INTO my_log (error_message) 
    VALUES (SQLEXCEPTION.message);
END;
like image 327
shurik2533 Avatar asked Oct 24 '11 09:10

shurik2533


1 Answers

DECLARE EXIT HANDLER FOR SQLEXCEPTION    
BEGIN

 GET DIAGNOSTICS CONDITION 1
    @p2 = MESSAGE_TEXT;

    INSERT INTO my_log (error_message) 
    SELECT @p2;
END;
like image 105
Rogerio de Moraes Avatar answered Sep 28 '22 18:09

Rogerio de Moraes