Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I get all the records of a table by passing its name as the parameter of MySQL stored procedure?
Suppose if we want to see all the records of a table by passing its name as the parameter of a stored procedure then following example will create a procedure named ‘details’ which accepts the name of the table as its parameter −
mysql> DELIMITER //
mysql> Create procedure details(tab_name Varchar(40))
-> BEGIN
-> SET @t:= CONCAT('Select * from',' ',tab_name);
-> Prepare stmt FROM @t;
-> EXECUTE stmt;
-> END //
Query OK, 0 rows affected (0.00 sec)
Now invoke this procedure by giving the name of the table as its parameter and it will show all the records of that table.
mysql> DELIMITER;
mysql> CALL details('student_detail');
+-----------+-------------+------------+
| Studentid | StudentName | address |
+-----------+-------------+------------+
| 100 | Gaurav | Delhi |
| 101 | Raman | Shimla |
| 103 | Rahul | Jaipur |
| 104 | Ram | Chandigarh |
| 105 | Mohan | Chandigarh |
+-----------+-------------+------------+
5 rows in set (0.02 sec)
Query OK, 0 rows affected (0.03 sec)Advertisements