Skip to main content
St Louis

Back to all posts

How to Call A Stored Procedure In MySQL?

Published on
3 min read
How to Call A Stored Procedure In MySQL? image

Best Books on MySQL Stored Procedures to Buy in October 2025

1 Murach's MySQL (4th Edition)

Murach's MySQL (4th Edition)

BUY & SAVE
$37.17 $59.50
Save 38%
Murach's MySQL (4th Edition)
2 MySQL Crash Course: A Hands-on Introduction to Database Development

MySQL Crash Course: A Hands-on Introduction to Database Development

BUY & SAVE
$34.09 $49.99
Save 32%
MySQL Crash Course: A Hands-on Introduction to Database Development
3 PHP & MySQL: Server-side Web Development

PHP & MySQL: Server-side Web Development

BUY & SAVE
$29.21 $45.00
Save 35%
PHP & MySQL: Server-side Web Development
4 MySQL Cookbook: 100+ recipes for database development and administration in MySQL (English Edition)

MySQL Cookbook: 100+ recipes for database development and administration in MySQL (English Edition)

BUY & SAVE
$29.95
MySQL Cookbook: 100+ recipes for database development and administration in MySQL (English Edition)
5 High Performance MySQL: Proven Strategies for Operating at Scale

High Performance MySQL: Proven Strategies for Operating at Scale

BUY & SAVE
$41.49 $65.99
Save 37%
High Performance MySQL: Proven Strategies for Operating at Scale
6 PHP and MySQL: The Comprehensive Guide to Server-Side Web Development with PHP 8 – Build Dynamic Websites with Database Integration, Security, and More (Rheinwerk Computing)

PHP and MySQL: The Comprehensive Guide to Server-Side Web Development with PHP 8 – Build Dynamic Websites with Database Integration, Security, and More (Rheinwerk Computing)

BUY & SAVE
$38.82 $59.95
Save 35%
PHP and MySQL: The Comprehensive Guide to Server-Side Web Development with PHP 8 – Build Dynamic Websites with Database Integration, Security, and More (Rheinwerk Computing)
7 MySQL Commands Cheat Sheet Reference Guide – Beginner to Advanced | Essential MySQL Commands for Database Management

MySQL Commands Cheat Sheet Reference Guide – Beginner to Advanced | Essential MySQL Commands for Database Management

BUY & SAVE
$14.99
MySQL Commands Cheat Sheet Reference Guide – Beginner to Advanced | Essential MySQL Commands for Database Management
8 High Performance MySQL: Optimization, Backups, Replication, and More

High Performance MySQL: Optimization, Backups, Replication, and More

  • AFFORDABLE PRICES ON QUALITY USED BOOKS IN GOOD CONDITION.
  • ECO-FRIENDLY CHOICE: REDUCE WASTE BY REUSING BOOKS.
  • FAST SHIPPING FOR PROMPT DELIVERY OF YOUR FAVORITE READS!
BUY & SAVE
$18.93 $49.99
Save 62%
High Performance MySQL: Optimization, Backups, Replication, and More
9 Hands-On MySQL Administration: Managing MySQL on Premises and in the Cloud

Hands-On MySQL Administration: Managing MySQL on Premises and in the Cloud

BUY & SAVE
$26.13 $79.99
Save 67%
Hands-On MySQL Administration: Managing MySQL on Premises and in the Cloud
+
ONE MORE?

To call a stored procedure in MySQL, you can use the "CALL" keyword followed by the name of the stored procedure and any input parameters that it requires within parentheses. For example, if you have a stored procedure named "getCustomerInfo" that takes a customer ID as a parameter, you can call it by executing the following query: CALL getCustomerInfo(1234);

Make sure you have the appropriate permissions to execute the stored procedure, and ensure that the procedure exists in the database before attempting to call it. Additionally, you can handle the result of the stored procedure by using the SELECT statement in combination with the CALL statement to fetch the output data.

How to pass default values to parameters in a stored procedure in MySQL?

In MySQL, you can pass default values to parameters in a stored procedure by using the "DEFAULT" keyword when declaring the parameter in the procedure definition. Here is an example:

  1. Create a stored procedure with default parameter values:

DELIMITER //

CREATE PROCEDURE my_procedure(IN param1 INT = 10, IN param2 VARCHAR(50) = 'default_value') BEGIN -- Your stored procedure logic here END//

DELIMITER ;

In the above example, the "param1" parameter has a default value of 10 and the "param2" parameter has a default value of 'default_value'.

  1. Call the stored procedure with or without passing values for the parameters:

CALL my_procedure(); -- This will use the default parameter values

CALL my_procedure(20, 'new_value'); -- This will override the default parameter values

By using default values in the stored procedure parameters, you can ensure that the procedure can be called with or without explicitly passing values for the parameters.

How to pass output parameters from a stored procedure in MySQL?

In MySQL, you can use OUT parameters in stored procedures to pass output values back to the calling program or script. Here is an example of how you can create a stored procedure with an output parameter:

  1. Create a stored procedure with an OUT parameter:

DELIMITER //

CREATE PROCEDURE GetTotalAmount(IN p_customer_id INT, OUT p_total_amount DECIMAL(10, 2)) BEGIN SELECT SUM(amount) INTO p_total_amount FROM orders WHERE customer_id = p_customer_id; END //

  1. Call the stored procedure and retrieve the output parameter value:

SET @customer_id = 123; CALL GetTotalAmount(@customer_id, @total_amount); SELECT @total_amount;

In this example, the stored procedure GetTotalAmount takes p_customer_id as an input parameter and p_total_amount as an output parameter. The procedure calculates the sum of the amount column from the orders table for the specified customer_id and assigns it to the output parameter.

To call the stored procedure, you need to set the input parameter value using a variable (@customer_id), call the procedure (CALL GetTotalAmount()), and then retrieve the output parameter value using another variable (@total_amount).

What is the syntax for calling a stored procedure in MySQL?

To call a stored procedure in MySQL, you can use the CALL statement followed by the name of the procedure and any input parameters that it requires.

Here is the general syntax for calling a stored procedure in MySQL:

CALL procedure_name(param1, param2, ...);

For example, if you have a stored procedure named getEmployeeById that takes an employee id as input parameter, you can call it like this:

CALL getEmployeeById(123);

Make sure to replace procedure_name with the actual name of the stored procedure you want to call, and param1, param2, ... with the actual input parameters required by the procedure.