How can we write MySQL stored procedure to select all the data from a table?

MySQLMySQLi Database

To demonstrate it we are creating a procedure named ‘selectdetails()’ which will fetch all the records from table ‘student_detail’.

mysql> Delimiter //
mysql> Create Procedure selectdetails()
   -> BEGIN
   -> Select * from student_detail;
   -> END//
Query OK, 0 rows affected (0.00 sec)

Now, after invoking this procedure, we will get all the records from ‘student_detail’ table.

mysql> Delimiter ;
mysql> CALL selectdetails();
+-----------+-------------+------------+
| Studentid | StudentName | address    |
+-----------+-------------+------------+
|       100 | Gaurav      | Delhi      |
|       101 | Raman       | Shimla     |
|       103 | Rahul       | Jaipur     |
|       104 | Ram         | Chandigarh |
|       105 | Mohan       | Chandigarh |
+-----------+-------------+------------+
5 rows in set (0.00 sec)
Query OK, 0 rows affected (0.01 sec)
raja
Published on 21-Feb-2018 14:42:50
Advertisements