A2-06-05.MySQL Stored Procedures That Return Multiple Values

轉載自:http://www.mysqltutorial.org/mysql-stored-procedures-return-multiple-values/php

(PHP部分沒有操做)mysql

MySQL Stored Procedures That Return Multiple Values

 

 Summary: in this tutorial, you will learn how to develop stored procedures that return multiple values.sql

MySQL stored function returns only one value. To develop stored programs that return multiple values, you need to use stored procedures with INOUT or OUT parameters.app

If you are not familiar with INOUT or OUT parameters, check it out the stored procedure’s parameters tutorial for the detailed information.ide

Stored procedures that return multiple values example

Let’s take a look at the orders table in the sample database.oop

orders table

The following stored procedure accepts customer number and returns the total number of orders that were shipped, canceled, resolved, and disputed.post

In addition to the IN parameter, the stored procedure takes four additional OUT parameters: shipped, canceled, resolved, and disputed. Inside the stored procedure, you use a SELECT statement with the COUNT function to get the corresponding total of orders based on the order’s status and assign it to the respective parameter.fetch

To use the get_order_by_cust stored procedure, you pass customer number and four user-defined variables to get the out values.this

After executing the stored procedure, you use the SELECT statement to output the variable values.spa

MySQL Stored Procedures That Return Multiple Values

Calling stored procedures that return multiple values from PHP

The following code snippet shows you how to call the stored procedure that returns multiple values from PHP.

The user-defined variables, which are preceded by the @ sign, are associated with the database connection, therefore, they are available for access between the calls.

In this tutorial, we have shown you how to develop a stored procedure that returns multiple values and how to call it from PHP.

相關文章
相關標籤/搜索