
- 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
How to use an OUT parameter / read data with SELECT from table in a MySQL procedure?
For this, you can use SELECT INTO. Let us first create a table −
mysql> create table DemoTable1860 ( Amount int ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1860 values(1590); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1860 values(410); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1860 values(3000); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
Mysql> select * from DemoTable1860;
This will produce the following output −
+--------+ | Amount | +--------+ | 1590 | | 410 | | 3000 | +--------+ 3 rows in set (0.00 sec)
Following is the query to create a stored procedure and use the OUT parameter −
mysql> delimiter // mysql> create procedure use_of_out_parameter(out TotalAmount int) begin select sum(Amount) into TotalAmount from DemoTable1860; end // Query OK, 0 rows affected (0.00 sec) mysql> delimiter ;
Call a stored procedure using call command −
mysql> call use_of_out_parameter(@TotalAmount); Query OK, 1 row affected (0.00 sec)
Now you can use the parameter variable −
mysql> select @TotalAmount;
This will produce the following output −
+--------------+ | @TotalAmount | +--------------+ | 5000 | +--------------+ 1 row in set (0.00 sec)
- Related Articles
- MySQL stored-procedure: out parameter?
- How can I create MySQL stored procedure with OUT parameter?
- How can we write MySQL stored procedure to select all the data from a table?
- MySQL procedure with SELECT to return the entire table
- How can I create MySQL stored procedure with IN parameter?
- How to use IF in stored procedure and select in MySQL?
- How to select all the data from a table using MySQL in Python?
- How to write MySQL procedure to insert data into a table?
- How to select data from a table where the table name has blank spaces in MYSQL?
- How can I create MySQL stored procedure with INOUT parameter?
- Insert data in a table in MySQL stored procedure?
- Select some data from a database table and insert into another table in the same database with MySQL
- How to use REPLACE() function with column’s data of MySQL table?
- How can I create a stored procedure to select values on the basis of some conditions from a MySQL table?
- Display table records from a stored procedure in MySQL

Advertisements