MySQL Forums
Forum List  »  Stored Procedures

table name as stored procedure parameter
Posted by: shaun merifield
Date: October 08, 2007 09:00AM

I realise this topic has probably been done to death but I cant seem to find a solution which works for me.

I want to call a stored procedure thus: call GetStakeholder("tablename", "unique_identifier", id);

I then want the procedure to return all records from the specified table using the unique identifier with the specified id.

It wont work. I realise this may require prepared statements but they dont seem to do it either.

Can someone post a working example of the syntax to get this working please. So far I *think* it should follow this format:

DELIMITER $$

DROP PROCEDURE IF EXISTS `eduplan`.`GetStakeholder`$$

CREATE PROCEDURE `eduplan`.`GetStakeholder`(usingtable varchar(255), usingid varchar(255), identifier varchar(255))
/*LANGUAGE SQL
| [NOT] DETERMINISTIC
| { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
| SQL SECURITY { DEFINER | INVOKER }
| COMMENT 'string'*/
BEGIN

SELECT
*
FROM
usingtable
WHERE
usingid = identifier
LIMIT 1;


END$$

DELIMITER ;

Cheers!

Options: ReplyQuote


Subject
Views
Written By
Posted
table name as stored procedure parameter
17248
October 08, 2007 09:00AM


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.