Error trapping in stored procedures

This is a discussion on Error trapping in stored procedures within the MySQL Database forums, part of the Database Forums category; I have the stored procedure below. It checks to see if the record exists then inserts. How would I trap ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-12-2007
mouac01@yahoo.com
 
Posts: n/a
Default Error trapping in stored procedures

I have the stored procedure below. It checks to see if the record
exists then inserts.
How would I trap an error if it fails on the insert? I read about
'Conditions and Handlers' but not sure how to implement it. I was
hoping there would be something like a 'IF UPDATED' clause similar to
'IF EXISTS'.
TIA...

CREATE PROCEDURE `sptest`(pID VARCHAR(10))
BEGIN
DECLARE vMsg VARCHAR(50);
IF EXISTS (SELECT id FROM sy_process WHERE id = pID) THEN
SET vMsg = 'Process already exist';
ELSE
INSERT INTO sy_process (id) VALUES (pID);
SET vMsg = 'Process inserted';
END IF;
SELECT vMsg as msg;
END $$

Reply With Quote
  #2 (permalink)  
Old 03-12-2007
Captain Paralytic
 
Posts: n/a
Default Re: Error trapping in stored procedures

On 12 Mar, 06:11, moua...@yahoo.com wrote:
> I have the stored procedure below. It checks to see if the record
> exists then inserts.
> How would I trap an error if it fails on the insert? I read about
> 'Conditions and Handlers' but not sure how to implement it. I was
> hoping there would be something like a 'IF UPDATED' clause similar to
> 'IF EXISTS'.
> TIA...
>
> CREATE PROCEDURE `sptest`(pID VARCHAR(10))
> BEGIN
> DECLARE vMsg VARCHAR(50);
> IF EXISTS (SELECT id FROM sy_process WHERE id = pID) THEN
> SET vMsg = 'Process already exist';
> ELSE
> INSERT INTO sy_process (id) VALUES (pID);
> SET vMsg = 'Process inserted';
> END IF;
> SELECT vMsg as msg;
> END $$


See my response to your other thread.

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:24 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0