MySQL Forums
Forum List  »  Stored Procedures

From a stored procedure access the SQLSTATE and Error Message and its error message
Posted by: biasik
Date: December 09, 2005 07:20PM

Hi All,

Is it possible from within a stored procedure to access and return the SQLSATE and it's associated error message, from a failed select, insert, delete or update.

I really do not want to set up a handler or condition for each scenario.

i.e.
DELIMITER //
DROP PROCEDURE IF EXISTS 'get_sqlstate//
CREATE PROCEDURE 'get_sqlstate' (
OUT p_name_returned TEXT,
OUT p_err_message TEXT)

BEGIN
--
-- Execptions.
DECLARE CONTINUE HANDLER FOR SQLEXPECTION
BEGIN
SET p_err_message = CONCAT(SQLSTATE - ', @SQLSTATE);
END;

SET p_err_message = 'Not Found';

SELECT
name
INTO
p_name_returned
FROM my_table
WHERE name = 'NICK';

SET p_err_message = '';

END//

DELIMITER ;

Options: ReplyQuote


Subject
Views
Written By
Posted
From a stored procedure access the SQLSTATE and Error Message and its error message
2965
December 09, 2005 07:20PM


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.