- 27.1 定义存储程序27.1 Defining Stored Programs
- 27.2 使用存储例程27.2 Using Stored Routines
- 27.3 使用触发器27.3 Using Triggers
- 27.4 使用事件调度器27.4 Using the Event Scheduler
- 27.5 使用视图27.5 Using Views
- 27.6 存储对象访问控制27.6 Stored Object Access Control
- 27.7 存储程序二进制日志27.7 Stored Program Binary Logging
- 27.8 存储程序的限制27.8 Restrictions on Stored Programs
- 27.9 视图的限制27.9 Restrictions on Views
本章讨论以 SQL 代码定义并存储在服务器上以供以后执行的数据库存储对象。This chapter discusses stored database objects that are defined in terms of SQL code that is stored on the server for later execution.
存储对象包括以下对象类型:Stored objects include these object types:
存储过程:使用
CREATE PROCEDURE创建的对象,并使用CALL语句调用。过程没有返回值,但可以修改其参数以便调用者稍后查看。它还可以生成要返回给客户端程序的结果集。Stored procedure: An object created withCREATE PROCEDUREand invoked using theCALLstatement. A procedure does not have a return value but can modify its parameters for later inspection by the caller. It can also generate result sets to be returned to the client program.存储函数:使用
CREATE FUNCTION创建的对象,使用起来类似内置函数。您可以在表达式中调用它,并且在表达式求值过程中返回一个值。Stored function: An object created withCREATE FUNCTIONand used much like a built-in function. You invoke it in an expression and it returns a value during expression evaluation.触发器:使用
CREATE TRIGGER创建并与表关联的对象。当表发生特定事件(例如插入或更新)时,触发器会被激活。Trigger: An object created withCREATE TRIGGERthat is associated with a table. A trigger is activated when a particular event occurs for the table, such as an insert or update.事件:使用
CREATE EVENT创建的对象,并由服务器根据计划调用。Event: An object created withCREATE EVENTand invoked by the server according to schedule.视图:使用
CREATE VIEW创建的对象,当引用时生成结果集。视图充当虚拟表。View: An object created withCREATE VIEWthat when referenced produces a result set. A view acts as a virtual table.
本文档使用的术语反映了存储对象的层级结构:Terminology used in this document reflects the stored object hierarchy:
存储例程包括存储过程和函数。Stored routines include stored procedures and functions.
存储程序包括存储例程、触发器和事件。Stored programs include stored routines, triggers, and events.
存储对象包括存储程序和视图。Stored objects include stored programs and views.
本章介绍如何使用存储对象。以下各节提供有关与这些对象相关的 SQL 语法以及对象处理的附加信息:This chapter describes how to use stored objects. The following sections provide additional information about SQL syntax for statements related to these objects, and about object processing:
对于每种对象类型,都有
CREATE、ALTER和DROP语句,用于控制哪些对象存在以及它们的定义方式。请参见 第 15.1 节,“数据定义语句”。For each object type, there areCREATE,ALTER, andDROPstatements that control which objects exist and how they are defined. See Section 15.1, “Data Definition Statements”.CALL语句用于调用存储过程。请参见 第 15.2.1 节,“CALL 语句”。TheCALLstatement is used to invoke stored procedures. See Section 15.2.1, “CALL Statement”.存储程序定义包含一个主体,该主体可以使用复合语句、循环、条件语句和已声明的变量。请参见 第 15.6 节,“复合语句语法”。Stored program definitions include a body that may use compound statements, loops, conditionals, and declared variables. See Section 15.6, “Compound Statement Syntax”.
存储程序引用对象的元数据变更会被检测到,并在程序下一次执行时自动解析受影响语句。更多信息请参见 第 10.10.3 节,“缓存已准备好的语句和存储程序”。Metadata changes to objects referred to by stored programs are detected and cause automatic reparsing of the affected statements when the program is next executed. For more information, see Section 10.10.3, “Caching of Prepared Statements and Stored Programs”.