MySQL Forums
Forum List  »  Stored Procedures

Re: problem with DECLARE CONTINUE HANDLER
Posted by: Peter Brawley
Date: August 21, 2012 12:14PM

Here's an example that works ...;


USE test ;
DROP TABLE IF EXISTS t;
CREATE TABLE t(i INT PRIMARY KEY, j INT) ;

DROP PROCEDURE IF EXISTS errhandlerdemo ;
DELIMITER go
CREATE PROCEDURE errhandlerdemo( pvalue INT, INOUT pResult VARCHAR(64) )
BEGIN
  BEGIN 
    DECLARE bad_key CONDITION FOR SQLSTATE '23000';
    DECLARE EXIT HANDLER FOR bad_key
    BEGIN
      SET pResult=CONCAT(pResult,'Insert failed; invalid key. ');
    END;
      SET pResult='Block 1 executed. ';
    INSERT INTO t VALUES( pvalue, NULL ) ;
    SET pResult=CONCAT(pResult,'Continuing after insert. ');
  END;
  SET pResult=CONCAT(pResult, 'Block 2 executed.');
END ;
go
DELIMITER ;
SET @result = NULL; CALL errhandlerdemo(NULL,@result);
SELECT @result;

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: problem with DECLARE CONTINUE HANDLER
1721
August 21, 2012 12:14PM


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.