MySQL Forums
Forum List  »  Stored Procedures

ambiguity in variable name and field name
Posted by: arun parajuli
Date: April 07, 2005 02:21AM

suppose we have a table:-

customer_info(customer_id,first_name,last_name);

and we are to write a stored procedure like below
************
create procedure sp_del_customer( IN customer_id char(17))
begin
delete from customer_info where customer_id=customer_id;
end;
************

above procedure deletes all the rows from the table customer_info because it can't distinguish between the variable name and the field name and hence evaluates the where clause true for every rows. There won't be problem if we were using @customer_id to denote the variable or if it had some thing else as its name.

To solve the problem, i am appending the table name before each field name like below
************
create procedure sp_del_customer( IN customer_id char(17))
begin
delete from customer_info a where a.customer_id=customer_id;
end;
************

is there any better solution..?

thanks in advance

Options: ReplyQuote


Subject
Views
Written By
Posted
ambiguity in variable name and field name
4643
April 07, 2005 02:21AM


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.