zoukankan      html  css  js  c++  java
  • oracle常用函数之case when

    一:case when 的两种用法

    1: case 字段名 when 字段值 then 希望值
                               when 字段值 then 希望值
                               else 希望值
           end

    2: case when 条件 then 希望值
                   when 条件 then 希望值
                   else 希望值
          end

    注:case 函数 只能返回一个值,当有满足条件的就会返回结果。

    示例: 

           select (case t.sex when '1' then '' when '0' then '' else t.sex end from emp t;
    
           select (case when t.sex ='1' then '' when t.sex= '0' then ''else t.sex end from emp t;

     

               我们利用case when 把sex为1的转化成男,把为0的转化成了女,其他的都不转化,现在我们稍微改下代码看下效果。

    这样当性别代码为1,0时转化成男、女,不为1,0显示成错误代码。

    二:case when 做条件

    select * from emp  t where t.sex = ( case  when t.sex =3  then t.sex  end );

  • 相关阅读:
    java多线程编程(一)
    java的本地文件操作
    Java基础总结(二)
    Gym 100851 Distance on Triangulation
    Gym 100851 题解
    Gym 101482 题解
    CodeForces Round 521 div3
    zoj 5823 Soldier Game 2018 青岛 I
    CodeForces round 520 div2
    CodeForces 1042 F Leaf Sets 贪心
  • 原文地址:https://www.cnblogs.com/devin818/p/7286141.html
Copyright © 2011-2022 走看看