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 December 2025

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

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

BUY & SAVE
$34.77 $49.99
Save 30%
MySQL Crash Course: A Hands-on Introduction to Database Development
2 Murach's MySQL (4th Edition) Professional SQL Book & Reference Guide with Cheat Sheets - Complete Database Development Training for Retrieving, Updating & Managing Data with AWS Integration

Murach's MySQL (4th Edition) Professional SQL Book & Reference Guide with Cheat Sheets - Complete Database Development Training for Retrieving, Updating & Managing Data with AWS Integration

BUY & SAVE
$37.17 $59.50
Save 38%
Murach's MySQL (4th Edition) Professional SQL Book & Reference Guide with Cheat Sheets - Complete Database Development Training for Retrieving, Updating & Managing Data with AWS Integration
3 PHP & MySQL: Server-side Web Development

PHP & MySQL: Server-side Web Development

BUY & SAVE
$29.17 $45.00
Save 35%
PHP & MySQL: Server-side Web Development
4 Murach's MySQL

Murach's MySQL

BUY & SAVE
$50.99 $57.50
Save 11%
Murach's MySQL
5 SQL: Learn SQL (using MySQL) in One Day and Learn It Well. SQL for Beginners with Hands-on Project. (Learn Coding Fast with Hands-On Project Book 5)

SQL: Learn SQL (using MySQL) in One Day and Learn It Well. SQL for Beginners with Hands-on Project. (Learn Coding Fast with Hands-On Project Book 5)

BUY & SAVE
$3.99
SQL: Learn SQL (using MySQL) in One Day and Learn It Well. SQL for Beginners with Hands-on Project. (Learn Coding Fast with Hands-On Project Book 5)
6 Front-End Back-End Development with HTML, CSS, JavaScript, jQuery, PHP, and MySQL

Front-End Back-End Development with HTML, CSS, JavaScript, jQuery, PHP, and MySQL

BUY & SAVE
$60.77 $95.00
Save 36%
Front-End Back-End Development with HTML, CSS, JavaScript, jQuery, PHP, and MySQL
7 Learning PHP, MySQL & JavaScript: A Step-by-Step Guide to Creating Dynamic Websites

Learning PHP, MySQL & JavaScript: A Step-by-Step Guide to Creating Dynamic Websites

BUY & SAVE
$43.61 $59.99
Save 27%
Learning PHP, MySQL & JavaScript: A Step-by-Step Guide to Creating Dynamic Websites
8 High Performance MySQL: Optimization, Backups, Replication, and More

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

  • AFFORDABLE OPTIONS WITH QUALITY ASSURANCE FOR BUDGET-CONSCIOUS READERS.
  • ECO-FRIENDLY CHOICE: PROMOTE SUSTAINABILITY BY BUYING USED BOOKS.
  • UNIQUE FINDS: ACCESS RARE TITLES AND OUT-OF-PRINT EDITIONS EASILY.
BUY & SAVE
$27.17 $49.99
Save 46%
High Performance MySQL: Optimization, Backups, Replication, and More
9 Learning MySQL: Get a Handle on Your Data

Learning MySQL: Get a Handle on Your Data

BUY & SAVE
$37.50 $65.99
Save 43%
Learning MySQL: Get a Handle on Your Data
+
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.