
- 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 can I create MySQL stored procedure with IN parameter?
To make it understand we are using the table named ‘student_info’ which have the following values −
mysql> Select * from student_info; +-----+---------+------------+------------+ | id | Name | Address | Subject | +-----+---------+------------+------------+ | 101 | YashPal | Amritsar | History | | 105 | Gaurav | Jaipur | Literature | | 110 | Rahul | Chandigarh | History | | 125 | Raman | Shimla | Computers | +------+--------+------------+------------+ 4 rows in set (0.00 sec)
Now, with the help of the following query, we will create a stored procedure with IN parameter which will show all the details of a particular student by providing the name as the parameter.
mysql> DELIMITER // ; mysql> Create PROCEDURE detail(IN S_Name VARCHAR(20)) -> BEGIN -> SELECT * From Student_info WHERE Name = S_Name; -> END // Query OK, 0 rows affected (0.16 sec) mysql> DELIMITER ;
S_Name is the IN parameter of the stored procedure ‘detail’. If we want to see all the details of the student name ‘Gaurav’ then it can be done with the help of the following query −
mysql> CALL detail('Gaurav'); +-----+--------+---------+------------+ | id | Name | Address | Subject | +-----+--------+---------+------------+ | 105 | Gaurav | Jaipur | Literature | +-----+--------+---------+------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.01 sec) mysql> CALL detail('Raman'); +-----+-------+---------+-----------+ | id | Name | Address | Subject | +-----+-------+---------+-----------+ | 125 | Raman | Shimla | Computers | +-----+-------+---------+-----------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.01 sec)
- Related Articles
- How can I create MySQL stored procedure with OUT parameter?
- How can I create MySQL stored procedure with INOUT parameter?
- MySQL stored-procedure: out parameter?
- How can I create a stored procedure to insert values in a MySQL table?
- How can I create a stored procedure to update values in a MySQL table?
- What is stored procedure and how can we create MySQL stored procedures?
- Create a stored procedure with delimiter in MySQL
- How can I create a stored procedure to delete values from a MySQL table?
- How can I create a MySQL stored procedure that returns multiple values from a MySQL table?
- How can a MySQL stored procedure call another MySQL stored procedure inside it?
- Create variables in MySQL stored procedure with DECLARE keyword
- How can we create MySQL stored procedure to calculate the factorial?
- How can we invoke MySQL stored procedure?
- How can I get all the records of a table by passing its name as the parameter of MySQL stored procedure?
- How can we alter a MySQL stored procedure?

Advertisements