MySQL Forums
Forum List  »  Stored Procedures

parametrize stored procedure
Posted by: Mehdi Alinoori
Date: May 01, 2014 08:45AM

Hi,
I have one code that is as below:

CREATE ROCEDURE `get_count`()
BEGIN
SELECT count(`id`) FROM `t1`;
END

so I want change this code to new code that I can count any filed form any table.
for example:

CREATE PROCEDURE `get_count`(IN filed VARCHAR(25),IN table VARCHAR(25))
BEGIN
SELECT count(`field`) FROM `table`;
END

so wehen we use get_count('id','t1') so this code run:
SELECT count(`id`) FROM `t1`;
or get_count('name','t2') so this code run:
SELECT count(`name`) FROM `t2`;
and etc....

is this possible?

thanks

Options: ReplyQuote


Subject
Views
Written By
Posted
parametrize stored procedure
1631
May 01, 2014 08:45AM
833
May 02, 2014 11:23PM
865
May 05, 2014 07:28PM


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.