MySQL Forums
Forum List  »  Stored Procedures

Procedure : CASE statement using SQL
Posted by: Tarun Bajaj
Date: September 04, 2012 02:28PM

I have a stored procedure that uses case statement.
Each When clause has an update statement.
I am trying to call this stored procedure multiple times and based on the pass parameter, I run an update statement.
Unfortunately, the update statement does not execute correctly. There are no changes done to the table if I pass the Input parameters to the update statement.
See code for detail.
Please guide.

-----
DROP PROCEDURE IF EXISTS p_updrec;
CREATE PROCEDURE `p_updrec`(
IN id varchar(10)
, IN n_str varchar(30)
, IN v_str varchar(30)
)
BEGIN

CASE n_str
WHEN n_str = 'profileStatus' THEN
UPDATE tbl_contact SET status = 'A' WHERE id = id;
-- The above statement updates the entire table instead of the right row
WHEN n_str = 'phoneNumberMobile' THEN
UPDATE tbl_contact SET mobile_phone = v_str
-- This does not do anything
END CASE;
END;

-----

Options: ReplyQuote


Subject
Views
Written By
Posted
Procedure : CASE statement using SQL
4004
September 04, 2012 02:28PM
1128
September 05, 2012 09:16PM


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.