Perform mathematical operations in a MySQL Stored Procedure?



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)
Updated on: 2019-12-24T07:41:15+05:30

835 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements