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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 $$ |
|
|||
|
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. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|