Perform mathematical operations in a MySQL Stored Procedure?

MySQLMySQLi Database

Let us create a stored procedure. Here, we are calculating amount*quantity i.e. implementing mathematical operations −

mysql> delimiter //
mysql> create procedure calculation_proc(amount int,quantity int)
     begin
     select amount,quantity,(amount*quantity) as Total;
     end
     //
Query OK, 0 rows affected (0.00 sec)
mysql> delimiter ;

Now you can call a stored procedure using call command −

mysql> call calculation_proc(250,3);

This will produce the following output −

+--------+----------+-------+
| amount | quantity | Total |
+--------+----------+-------+
|    250 |        3 |   750 |
+--------+----------+-------+
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
raja
Published on 24-Dec-2019 07:41:15
Advertisements