转载自:http://www.mysqltutorial.org/mysql-stored-procedure-tutorial.aspx
MySQL Stored Procedure
In this section, you will learn step by step how to develop stored procedures in MySQL. First, we introduce you to the stored procedure concept and discuss when you should use it. Then, we show you how to use the basic elements of the procedure code such as create procedure statement, if-else, case, loop, stored procedure’s parameters.
Each tutorial is packed with easy-to-understand examples and detailed explanations. If you go through the entire tutorials, you can develop from simple to complex stored procedures in MySQL.
Introduction to MySQL Stored Procedures
This tutorial introduces to you MySQL stored procedures, their advantages and disadvantages.
Getting Started with MySQL Stored Procedures
In this tutorial, we will show you step by step how to develop the first MySQL stored procedure by using the CREATE PROCEDURE statement. In addition, we will show you how to call the stored procedure from SQL statements.
MySQL Stored Procedure Variables
You will learn about variables in MySQL stored procedure, how to declare and use variables. In addition, scope of variable is also covered
MySQL Stored Procedure Parameters
This tutorial shows you how to define parameters in stored procedure and introduces you to different parameter modes including IN, OUT and INOUT.
MySQL Stored Procedures That Return Multiple Values
This tutorial shows you how to develop stored procedures that return multiple values.
MySQL IF Statement
This tutorial shows you how to use MySQL IF statement to execute a block of SQL code based on conditions.
MySQL CASE Statement
You will learn how to use MySQL CASE statements to construct complex conditionals. We will show you how to use both simple and searched CASE statements.
Hints for Choosing Between IF and CASE Statements
We will give you some hints so that you can choose between IF and CASE statement in stored procedures.
MySQL Loop in Stored Procedures
In this tutorial, you will learn how to use various loop statements in stored procedure to execute a block of code repeatedly based on a given Boolean condition.
MySQL Cursor
Shows you how to use MySQL cursor in stored procedures to loop over a result set and process each row at a time.
Listing Stored Procedures in a MySQL Database
In this tutorial, we will show you how to list all stored procedures in a MySQL database. We also provide you with a statement that displays stored procedure's code.
MySQL Error Handling in Stored Procedures
This tutorial shows you how to use MySQL handler to handle exceptions or errors encountered in stored procedures.
Raising Error Conditions with MySQL SIGNAL / RESIGNAL Statements
In this tutorial, you will learn how to use MySQL SIGNAL and RESIGNAL statements to raise error conditions inside stored procedures.
MySQL Stored Function
In this tutorial, you will learn how to create MySQL stored functions using CREATE FUNCTION statement.