MySQL - 5.1 Reference Manual参考手册 - 12.8.6.2. CASE Statement - CASE语句
2009-02-10 15:18
761 查看
MySQL - 5.1 Reference Manual参考手册 - 12.8.6.2. CASE Statement - CASE语句
CASE [code]case_value
WHEN
when_valueTHEN
statement_list
[WHEN
when_valueTHEN
statement_list] ...
[ELSE
statement_list]
END CASE
[/code]
Or:
CASE WHEN [code]search_conditionTHEN
statement_list
[WHEN
search_conditionTHEN
statement_list] ...
[ELSE
statement_list]
END CASE
[/code]
The
CASE
statement for stored programs implements a complex conditional
construct. If a
search_condition
evaluates to true, the corresponding SQL statement list is
executed. If no search condition matches, the statement list in
the
ELSEclause is executed. Each
statement_listconsists of one or
more statements.
If no
when_valueor
search_conditionmatches the value
tested and the
CASE
statement contains no
ELSEclause, a
Case not found for CASE statement error
results.
Each
statement_listconsists of one
or more statements; an empty
statement_listis not allowed. To
handle situations where no value is matched by any
WHENclause, use an
ELSE
containing an empty
BEGIN ... ENDblock, as
shown in this example:
DELIMITER | CREATE PROCEDURE p() BEGIN DECLARE v INT DEFAULT 1; CASE v WHEN 2 THEN SELECT v; WHEN 3 THEN SELECT 0; ELSE BEGIN END; END CASE; END; |
(The indentation used here in the
ELSEclause
is for purposes of clarity only, and is not otherwise
significant.)
Note
The syntax of theCASE
statement used inside stored programs
differs slightly from that of the SQL
CASE
expression described in
Section 11.3, “Control Flow Functions”. The
CASE
statement cannot have an
ELSE NULLclause,
and it is terminated with
END CASEinstead
of
END.
[MySQL - 5.1 Reference Manual 参考手册 - 12 SQL Statement Syntax
- SQL语句语法 - 12.8 MySQL Compound-Statement Syntax - MySQL复合语句语法 - 12.8.6
Flow Control Constructs流程控制结构 - 12.8.6.2. CASE Statement - CASE语句 - 文档]
http://dev.mysql.com/doc/refman/5.1/en/case-statement.html[MySQL - 5.1 Reference Manual参考手册]
MySQL- 5. 数据库管理 - 5.3. mysqld:MySQL服务器 - 5.3.3. 服务器系统变量 -
max_allowed_packet, http://dev.mysql.com/doc/refman/5.1/zh/database-administration.html#server-system-variables
9.
语言结构 - 9.2. 数据库、表、索引、列和别名 - 9.2.2. 识别符大小写敏感性, http://dev.mysql.com/doc/refman/5.1/zh/language-structure.html#name-case-sensitivity
13. SQL语句语法 - 13.1. 数据定义语句 - 13.1.5. CREATE TABLE语法, http://dev.mysql.com/doc/refman/5.1/zh/sql-syntax.html#create-table 12
SQL Statement Syntax - SQL语句语法 - 12.8 MySQL Compound-Statement Syntax -
MySQL复合语句语法 - 12.8.6 Flow Control Constructs流程控制结构 - 12.8.6.2. CASE
Statement - CASE语句, http://dev.mysql.com/doc/refman/5.1/en/case-statement.html
相关文章推荐
- MySQL - 翻译 - 5.1 Reference Manual参考手册 - 5.1.3 Server System Variables服务器系统变量 - max_heap_table_size
- MySQL - MySQL 5.1参考手册 - 第13章:SQL语句语法 - 13.1. 数据定义语句 - CREATE TABLE
- MySQL 5.7 Reference Manual Chapter 4 Tutorial 参考手册第四章教程内容总结
- MySQL 5.7 Reference Manual Chapter 10 Language Structure 参考手册第十章语言结构内容总结
- PHP - Manual手册 - Function Reference函数参考 - Database Extensions数据库扩展 - Vendor Specific Database Extensions特定提供商数据库扩展 - MySQL - MyS
- MySQL - MySQL 5.1参考手册 - 13. SQL语句语法 - 13.1. 数据定义语句 - 13.1.5. CREATE TABLE语法
- MySQL 5.1参考手册 :: 13. SQL语句语法
- MySQL 5.7 Reference Manual Chapter 13 Functions and Operators 参考手册第十三章函数与操作符内容总结
- PHP - Manual手册 - Function Reference函数参考 - File System Related Extensions文件系统相关扩展 - Filesystem文件系统 - Filesystem Functions文件系统函数 -
- MySQL 5.1 参考手册CHM (官方 简体中文版)
- PHP - Manual手册 - Function Reference函数参考 - Session Extensions会话扩展 - Session Handling会话操作 - Installing/Configuring安装/配置 - Runtime
- MySQL 5.1参考手册
- MySQL 5.1参考手册学习笔记 第1章:一般信息
- PHP - Manual手册 - Function Reference函数参考 - Text Processing文本处理 - Strings字符串 - String Functions字符串函数 - strip_tags字符串中去除HTML和PHP标记
- MySQL 5.1参考手册(摘录)
- (大数据工程师学习路径)第五步 MySQL参考手册中文版----MySQL语句语法
- MySQL 5.1参考手册
- MySQL 5.1参考手册
- MySQL 5.1参考手册 :: 7. 优化
- MySQL 5.1参考手册