Oracle/PLSQL: Case Statement
In Oracle 9i, you can use the case statement within an SQL statement. It has the functionality of an IF-THEN-ELSE statement.
译:在Oracle 9i中,你可以在SQL语句中使用case条件。它具有IF-THEN-ELSE条件的功能。
The syntax for the case statement is:
译:语法如下
CASE expression
WHEN condition_1 THEN result_1
WHEN condition_2 THEN result_2
...
WHEN condition_n THEN result_n
ELSE result END
expressionis the value that you are comparing to the list of conditions. (ie: condition_1, condition_2, ... condition_n)
译:expression就是要与条件比较的值。(例如:条件condition_1, condition_2, ... condition_n)
condition_1to condition_n must all be the same datatype. Conditions are evaluated in the order listed. Once a condition is found to be true, the case statement will return the result and not evaluate the conditions any further.
译:条件condition_1condition_n必须具有相同的数据类型。条件是按列表顺序赋值,一旦一个条件为真了,case条件就会返回结果并且不会再次去执行该条件了
result_1to result_n must all be the same datatype. This is the value returned once a condition is found to be true.
译:结果result_1result_必须具有相同的数据类型。一旦有条件成立,这就是返回的值。
Note:
注:
If no condition is found to be true, then the case statement will return the value in the ELSE clause.
译:如果没有找到为真的条件,case将返回ELSE条件中值。
If the ELSE clause is omitted and no condition is found to be true, then the case statement will return NULL.
译:如果省略了ELSE条件并且也没有找到为真的条件,case条件将返回NULL。
You can have up to 255 comparisons in a case statement. Each WHEN ... THEN clause is considered 2 comparisons.
译:在case条件中最多可以有255个比较,每个WHEN ... THEN子被认为两次比较。
For Example:
You could use the case statement in an SQL statement as follows:
译:你可以在SQL语句中像如下使用case语句:
select table_name,
CASE owner
WHEN 'SYS' THEN 'The owner is SYS'
WHEN 'SYSTEM' THEN 'The owner is SYSTEM'
ELSE 'The owner is another value' END
from all_tables;
The above case statement is equivalent to the following IF-THEN-ELSE statement:
译:下面的case条件等价于下面的IF-THEN-ELSE语句:
IF owner = 'SYS' THEN
     result := 'The owner is SYS';
ELSIF owner = 'SYSTEM' THEN
    result := 'The owner is SYSTEM'';
ELSE
    result := 'The owner is another value';
END IF;
The case statement will compare each owner value, one by one.
译:case条件将一个一个的比较每个所有者的值:
One thing to note is that the ELSE clause within the case statement is optional. You could have omitted it. Let's take a look at the SQL statement above with the ELSE clause omitted.
译:要注意的一个就是ELSE在case条件中可选的,你可以省略它。让我们看一个关于上面语句省略ELSE的SQL语句。
Your SQL statement would look as follows:
select table_name,
CASE owner
WHEN 'SYS' THEN 'The owner is SYS'
WHEN 'SYSTEM' THEN 'The owner is SYSTEM' END
from all_tables;
With the ELSE clause omitted, if no condition was found to be true, the case statement would return NULL.
译:省略了ELSE条件,且没有找到为真的条件,case就会返加NULL

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

Oracle/PLSQL Case Statement相关推荐

  1. Oracle/PLSQL FETCH Statement

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! Orac ...

  2. oracle pl sql case,oracle plsql case when_end case小记

    create or replace function func_1_2_mv_orderstatus(in_orderbill_status in portal_orderbill.orderbill ...

  3. Oracle/PLSQL WHERE CURRENT OF Statement

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! Orac ...

  4. oracle plsql 使用

    在PLSQL, sql语句中 where 带有中文的查询条件查询不到数据 发现是PLSQL字符编码问题.解决办法就是设置一个系统环境变量就好了.右击"计算机"-"属性&q ...

  5. 【转】oracle PLSQL基础学习

    [转]oracle PLSQL基础学习 --oracle 练习: /**************************************************PL/SQL编程基础****** ...

  6. mysql plsql循环语句吗,Oracle PLSQL 在游标中用while循环实例程序

    Oracle PLSQL 在游标中用while循环实例程序 Oracle PLSQL 在游标中用while循环实例程序 Oracle PLSQL 在游标中用while循环实例程序 declare cu ...

  7. lower() oracle,PLSQL LOWER用法及代码示例

    PLSQL LOWER函数用于将指定字符串中的所有字母都转换为小写.如果字符串中的字符不是字母,则不受此功能的影响. 要转换的char可以是任何数据类型,例如CHAR,VARCHAR2,NCHAR,N ...

  8. Oracle PLSQL 导出数据table xx contains one or more CLOB columns 解决方案

    Oracle PLSQL 导出数据table xx contains one or more CLOB columns 解决方案 参考文章: (1)Oracle PLSQL 导出数据table xx ...

  9. oracle函数 case,oracle的case函数和case控制结构 (摘)

    oracle的case函数和case控制结构 =========================================================== 作者: zhouwf0726(ht ...

最新文章

  1. C#获取指定坐标点像素,效率更高快
  2. eclipse java代码颜色设置颜色设置颜色设置颜色设置颜色_eclipse设置(颜色,字体等)...
  3. char [] 和 char * 区别
  4. python对象编程例子-python面向对象编程练习
  5. win7下编译uCOS-II
  6. 字符指针(子串个数统计)
  7. 天平应什么放置_天平是否应该放干燥剂?
  8. 设计模式六大原则(3)——依赖倒置原则
  9. java akka_用于大型事件处理的Akka Java
  10. 电子邮件客户端程序_您更喜欢哪个电子邮件客户端?
  11. 实现Ecshop商品跳到淘宝、京东等的购买链接
  12. 程序阻碍OD调试的方式1
  13. LNMP一键安装脚本使用 离线安装
  14. Python之pip安装出现报错ERROR: Cannot unpack file
  15. 【科研绘图】用PPT进行科研用图的图片预处理
  16. MySQL复制表数据到新表的方法
  17. 21秋期末考试建设工程法规10221k1
  18. 学信网电子学历备案表怎么弄
  19. Tibco Designer -- 循环遍历
  20. 信号完整性分析中,普遍选用50Ω特性阻抗的原因

热门文章

  1. 零代码以“王者荣耀”为例解析设计七原则
  2. 云图说 | 快速创建一个kubernetes集群
  3. 17张图带你解析红黑树的原理!保证你能看懂!
  4. 云图说|小云妹-DDS实例安全基本操作
  5. 红橙Darren视频笔记 流式布局tagLayout measure layout方法学习 adapter使用 学习感悟
  6. 三分钟完全了解PyTorch中卷积层内部计算方法和权值初始值的来历,让你对模型有更深层次的理解
  7. 全国计算机等级英语一级考试,全国计算机等级考试职业英语一级考试大纲
  8. php程序员的情书,只有程序员才看得懂的情书
  9. php关联数组json,使用JSON从PHP到Javascript的关联数组
  10. java mybatis 搭建_mybatis环境搭建(转载)