How can we create MySQL stored procedures without ‘BEGIN’ and ‘END’?


We can create MySQL stored procedures without ‘BEGIN’ and ‘END’ just in the same way created with both of them only thing is to omit to BEGIN and END. In the following example, we are creating a stored procedure without ‘BEGIN’ and ‘END’ to get all the rows from a table −

Example

mysql> Delimiter //
mysql> CREATE PROCEDURE Hello()
    -> SELECT * from Student_info; //
Query OK, 0 rows affected (0.08 sec)

We can see MySQL created stored procedures without BEGIN and END. Now invoke this by CALL statement −

mysql> Delimiter ;

mysql> CALL Hello();
+-----+---------+------------+------------+
| id  | Name    | Address    | Subject    |
+-----+---------+------------+------------+
| 101 | YashPal | Amritsar   | History    |
| 105 | Gaurav  | Chandigarh | Literature |
| 125 | Raman   | Shimla     | Computers  |
+------+---------+------------+------------+
3 rows in set (0.18 sec)
Query OK, 0 rows affected (0.28 sec)

Updated on: 22-Jun-2020

330 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements