设为首页 收藏本站
查看: 506|回复: 0

[经验分享] MySQL

[复制链接]

尚未签到

发表于 2016-10-18 09:04:52 | 显示全部楼层 |阅读模式
MySQL - 5.1 Reference Manual参考手册 - 12.8.6.2. CASE Statement - CASE语句



CASE case_value
    WHEN when_value THEN statement_list
    [WHEN when_value THEN statement_list] ...
    [ELSE statement_list]
END CASE

  
Or:


CASE
    WHEN search_condition THEN statement_list
    [WHEN search_condition THEN statement_list] ...
    [ELSE statement_list]
END CASE

  
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 ELSE clause is executed. Each
statement_list consists of one or
more statements.

  
If no when_value or
search_condition matches the value
tested and the
CASE
statement contains no ELSE clause, a
Case not found for CASE statement error
results.

  
Each statement_list consists of one
or more statements; an empty
statement_list is not allowed. To
handle situations where no value is matched by any
WHEN clause, use an ELSE
containing an empty BEGIN ... END block, 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 ELSE clause
is for purposes of clarity only, and is not otherwise
significant.)


Note
  
The syntax of the
CASE
statement used inside stored programs
differs slightly from that of the SQL
CASE
expression described in
Section11.3, “Control Flow Functions”. The
CASE
statement cannot have an ELSE NULL clause,
and it is terminated with END CASE instead
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

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-287759-1-1.html 上篇帖子: jsp存取mysql中文数据结果为乱码的解决方法 下篇帖子: 使用复制来提升MySQL的高可用性和处理能力
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表