# 第三章 存储过程

在本节中，您将逐步学习如何在MySQL中编写和开发存储过程。 首先，我们向您[介绍存储过程的概念](http://www.yiibai.com/mysql/introduction-to-sql-stored-procedures.html)，并讨论何时使用它。 然后，展示如何使用过程代码的基本元素，如[创建存储过程的语句](http://www.yiibai.com/mysql/getting-started-with-mysql-stored-procedures.html)，[if-else](http://www.yiibai.com/mysql/if-statement.html)，[case](http://www.yiibai.com/mysql/case-statement.html)，[loop](http://www.yiibai.com/mysql/stored-procedures-loop.html)，[存储过程的参数](http://www.yiibai.com/mysql/stored-procedures-parameters.html)。

下面每个教程都包含了易于理解的示例和详细的说明。 如果您浏览并学习所有教程，您可以开发MySQL中由简单到复杂的存储过程。

**1.MySQL存储过程简介** 本教程介绍了MySQL存储过程，它们的优缺点。 参考：<http://www.yiibai.com/mysql/introduction-to-sql-stored-procedures.html>

**2.MySQL存储过程入门** 在本教程中，我们将逐步介绍如何使用`CREATE PROCEDURE`语句开发第一个MySQL存储过程。 另外，还将展示如何从SQL语句调用存储过程。 参考：<http://www.yiibai.com/mysql/getting-started-with-mysql-stored-procedures.html>

**3.MySQL存储过程变量** 了解并学习MySQL存储过程中的变量，如何声明和使用变量。 另外还包括变量的范围。 参考：<http://www.yiibai.com/mysql/variables-in-stored-procedures.html>

**4.MySQL存储过程参数**

本教程将向您介绍如何在存储过程中定义参数，并介绍不同的参数模式，包括`IN`，`OUT`和`INOUT`。 参考： <http://www.yiibai.com/mysql/stored-procedures-parameters.html>

**5.返回多个值的MySQL存储过程** 本教程将向您展示如何开发返回多个值的存储过程。 参考：<http://www.yiibai.com/mysql/stored-procedures-return-multiple-values.html>

**6.MySQL IF语句** 本教程将向您展示如何使用MySQL `IF`语句根据条件执行一个SQL代码块。 参考：<http://www.yiibai.com/mysql/if-statement.html>

**7.MySQL CASE语句** 将学习如何使用MySQL `CASE`语句构建复杂条件。并展示如何使用简单和搜索的`CASE`语句。 参考：<http://www.yiibai.com/mysql/case-statement.html>

**8.在IF和CASE语句使用技巧** 我们将给出一些使用技巧，以便可以在存储过程中选择`IF`和`CASE`语句。 参考：<http://www.yiibai.com/mysql/conditional-control-if-case-statement-stored-procedures.html>

**9.存储过程中的MySQL循环** 在本教程中，您将学习如何在存储过程中使用各种循环语句，以基于给定的布尔条件重复执行代码块。

参考：<http://www.yiibai.com/mysql/stored-procedures-loop.html>

**10.MySQL游标** 显示如何在存储过程中使用MySQL游标循环遍历结果集并一次处理每一行。 参考：<http://www.yiibai.com/mysql/cursor.html>

**11.在MySQL数据库中列出存储过程** 在本教程中，我们将向您展示如何列出MySQL数据库中的所有存储过程。 我们还提供一个显示存储过程代码的语句。 参考：<http://www.yiibai.com/mysql/listing-stored-procedures-in-mysql-database.html>

**12.存储过程中的MySQL错误处理** 本教程将向您展示如何使用MySQL处理程序来处理在存储过程中遇到的异常或错误。 参考：<http://www.yiibai.com/mysql/error-handling-in-stored-procedures.html>

**13.使用MySQL SIGNAL/RESIGNAL语句引发错误条件**

在本教程中，您将学习如何使用MySQL `SIGNAL`和`RESIGNAL`语句来触发存储过程中的错误条件。 参考：<http://www.yiibai.com/mysql/signal-resignal.html>

**14.MySQL存储函数**

在本教程中，您将学习如何使用`CREATE FUNCTION`语句创建MySQL存储函数。 参考：<http://www.yiibai.com/mysql/stored-function.html>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hezhiqiang-book.gitbook.io/mysql/di-san-zhang.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
