MySQL Forums
Forum List  »  Stored Procedures

Re: Inserting errors into logs
Posted by: Peter Brawley
Date: April 20, 2020 11:29AM

Minimally...

CREATE PROCEDURE errdemo( pvalue INT, OUT pResult INT )
BEGIN
  DECLARE bad_key CONDITION FOR SQLSTATE '23000';
  DECLARE EXIT HANDLER FOR bad_key
    BEGIN
      INSERT INTO errlog 
        SET dt=Now(),msg=Concat('Insert on t failed; bad key.');
      SET presult=-1;
      ROLLBACK;
    END;
  START TRANSACTION;
    INSERT INTO t VALUES( pvalue, NULL ) ;
    SET pResult=Row_Count();
    COMMIT;
  END;
END;

Options: ReplyQuote


Subject
Views
Written By
Posted
897
April 20, 2020 07:10AM
Re: Inserting errors into logs
485
April 20, 2020 11:29AM
468
April 22, 2020 06:58AM
479
April 22, 2020 02:45PM
408
April 23, 2020 12:38AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.