MySQL Forums
Forum List  »  General

using variables as field names in Stored Procedures
Posted by: Craig
Date: March 17, 2005 06:07AM

hey all,

i can't seem to figure out how to specify a field name in a stored procedure using a variable:

for example, in a table which has a unique entryID, then 5 fields which are called f1,f2...f5.

i would like to be able to do this:

CREATE PROCEDURE changeStat(IN entryID INT, IN fieldName VARCHAR(10), IN value INT)
BEGIN
UPDATE userStats SET fieldName = value WHERE tableName.entryID = entryID;
END//

creating this stored procedure is fine, but when it's run i get this error:
Unknown column 'fieldName' in 'field list'.

in reality the table i am using is a lot bigger than 5 fields, and i would prefer not to hardcode a huge switch statement with the correct statement being called for the fieldName which is passed in.

cheers,
Craig

Options: ReplyQuote


Subject
Written By
Posted
using variables as field names in Stored Procedures
March 17, 2005 06:07AM


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.