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

MySQLMySQLi Database

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)
raja
Published on 21-Feb-2018 15:36:31
Advertisements