MySQL 实验室 因为专注,所以专业。

  • 首页
  • 博客
  • 下载
  • 文档
  • 工具
  • 知识库
  • 培训及服务
  • MySQL 5.1 Reference Manual :: 19 Stored Programs and Views
    • MySQL 5.1 Reference Manual
    • Preface, Notes, Licenses
    • 1 General Information
    • 2 Installing and Upgrading MySQL
    • 3 Tutorial
    • 4 MySQL Programs
    • 5 MySQL Server Administration
    • 6 Backup and Recovery
    • 7 Optimization
    • 8 Language Structure
    • 9 Internationalization and Localization
    • 10 Data Types
    • 11 Functions and Operators
    • 12 SQL Statement Syntax
    • 13 Storage Engines
    • 14 High Availability and Scalability
    • 15 MySQL Enterprise Monitor
    • 16 Replication
    • 17 MySQL Cluster NDB 6.X/7.X
    • 18 Partitioning
    • 19 Stored Programs and Views
    • 20 INFORMATION_SCHEMA Tables
    • 21 Connectors and APIs
    • 22 Extending MySQL
    • A MySQL 5.1 Frequently Asked Questions
    • B Errors, Error Codes, and Common Problems
    • C MySQL Change History
    • D Restrictions and Limits
    • Index
    • Standard Index
    • C Function Index
    • Command Index
    • Function Index
    • INFORMATION_SCHEMA Index
    • Transaction Isolation Level Index
    • JOIN Types Index
    • Operator Index
    • Option Index
    • Privileges Index
    • SQL Modes Index
    • Status Variable Index
    • Statement/Syntax Index
    • System Variable Index

    Chapter 19. Stored Programs and Views

    Table of Contents     [+/-]

    19.1. Defining Stored Programs
    19.2. Using Stored Routines (Procedures and Functions)     [+/-]
    19.2.1. Stored Routine Syntax
    19.2.2. Stored Routines and MySQL Privileges
    19.2.3. Stored Routine Metadata
    19.2.4. Stored Procedures, Functions, Triggers, and LAST_INSERT_ID()
    19.3. Using Triggers     [+/-]
    19.3.1. Trigger Syntax
    19.3.2. Trigger Metadata
    19.4. Using the Event Scheduler     [+/-]
    19.4.1. Event Scheduler Overview
    19.4.2. Event Scheduler Configuration
    19.4.3. Event Syntax
    19.4.4. Event Metadata
    19.4.5. Event Scheduler Status
    19.4.6. The Event Scheduler and MySQL Privileges
    19.5. Using Views     [+/-]
    19.5.1. View Syntax
    19.5.2. View Processing Algorithms
    19.5.3. Updatable and Insertable Views
    19.5.4. View Metadata
    19.6. Access Control for Stored Programs and Views
    19.7. Binary Logging of Stored Programs

    This chapter discusses stored programs and views, which are database objects defined in terms of SQL code that is stored on the server for later execution.

    Stored programs include these objects:

    • Stored routines, that is, stored procedures and functions. A stored procedure is invoked using the CALL statement. 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. A stored function is used much like a built-in function. you invoke it in an expression and it returns a value during expression evaluation.

    • Triggers. A trigger is a named database object that is associated with a table and that is activated when a particular event occurs for the table, such as an insert or update.

    • Events. An event is a task that the server runs according to schedule.

    Views are stored queries that when referenced produce a result set. A view acts as a virtual table.

    This chapter describes how to use stored programs and views. The following sections provide additional information about SQL syntax for statements related to these objects:

    • For each object type, there are CREATE, ALTER, and DROP statements that control which objects exist and how they are defined. See Section 12.1, “Data Definition Statements”.

    • The CALL statement is used to invoke stored procedures. See Section 12.2.1, “CALL Syntax”.

    • Stored program definitions include a body that may use compound statements, loops, conditionals, and declared variables. See Section 12.7, “MySQL Compound-Statement Syntax”.