MySQL Forums
Forum List  »  Stored Procedures

Re: ambiguity in variable name and field name
Posted by: Andrew Gilfrin
Date: April 07, 2005 04:51AM

The obvious answer is don't use the same name as the column for the parameter. In Oracle it's possible to prefix the parameter name with the procedure name as you have done with the table name. I don't think (but I'm not sure) that this is possible in MySQL.

I don't have access to a MySQL system right now but I'd imagine your solution doesn't actually work and still may compare the column to it's self. It will certainly open up that possiblity.

I'd personally suggest a naming convention for parameters, something as simple as a p_ in the front of parameter to distingusih that they are parameters rather than table columns. It's not that different from using a table alias as you have done.

This would look something like.

create procedure sp_del_customer( IN p_customer_id char(17))
begin
delete from customer_info a where a.customer_id=p_customer_id;
end;

At the end of the day you can define any names you like (within reason) so it's up to you. Personally I'd avoid any chance of ambiguity and not name the parameter the exactly the same as the column.

Andrew Gilfrin
------------------
http://gilfster.blogspot.com
My MySQL related Blog

http://www.mysqldevelopment.com
MySQL Stored Procedure,Trigger, View.... (Just about most things these days) Information

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: ambiguity in variable name and field name
6750
April 07, 2005 04:51AM


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.