
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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)
- Related Articles
- MySQL Stored procedure to declare two values and perform mathematical operation
- How can we perform ROLLBACK transactions inside a MySQL stored procedure?
- How can we perform START transactions inside MySQL stored procedure?
- How can we perform COMMIT transactions inside MySQL stored procedure?
- How can a MySQL stored procedure call another MySQL stored procedure inside it?
- How to perform mathematical operations on elements of a list in R?
- Set conditions in a MySQL stored procedure
- Create a stored procedure with delimiter in MySQL
- Implement Conditional MySQL Query in a stored procedure?
- MySQL stored-procedure: out parameter?
- MySQL stored procedure return value?
- MySQL Stored Procedure to create a table?
- Working with WHERE IN() in a MySQL Stored Procedure
- Insert data in a table in MySQL stored procedure?
- Perform NAND/NOR operations in MySQL

Advertisements