zoukankan      html  css  js  c++  java
  • Mysql储存过程7: case

    #用在储存过程中:

    create
    procedure k() begin declare number int; set number = floor(rand(0)*2); case number when number > 0 then select '>0'; else select '=0'; end case; end$

    #用在查询中:
    select case user when 'root' then 'yes' else 'no' end from mysql.user;

    select case when user='root' then 'yes' else 'no' end from mysql.user;

    注意这个case用在储存过程中与用在查询语句中是不一样的。

    储存过程中要用end case结束, 用在一般查询中是end结束。

    #储存过程case语法
    case value
      when 条件 then
      SQL
      [when 条件 then]
      SQL
      [else]
      SQL
      end case;
    
    #用在搜索中的case语法:
    1.case when column=value then 'output1' else 'output2' end from database.table;
    2.case column when 'value' then 'output1' else 'output2' end from database.table;
    
    
    select case when column=value then 'output1' else 'output2' end  from database.table;
    
    mysql> select user,case  when user='root' then 'yes' else 'no' end from mysql.user;$
    +------+-------------------------------------------------+
    | user | case  when user='root' then 'yes' else 'no' end |
    +------+-------------------------------------------------+
    | root | yes                                             |
    | root | yes                                             |
    | root | yes                                             |
    +------+-------------------------------------------------+

     

    用法可参以参考一下这里:

    http://www.cnblogs.com/perl6/p/6995593.html

     

  • 相关阅读:
    【大胃王】2013暴食女王巅峰战(安吉拉x三宅x正司x木下)熟肉+高能
    破解 CrackMe#1 [UBC] by bRaINbuSY
    栈实现符号平衡检测
    简单的栈
    数独算法
    win32绘图基础
    Win32基础知识整理
    Win32最简单的程序
    初学layer
    android 虚线
  • 原文地址:https://www.cnblogs.com/perl6/p/7114742.html
Copyright © 2011-2022 走看看