一. if/else

语法:
if 条件表达式 then
语句块;
if 条件表达式 then

语句块
end if;
elsif 条件表达式 then
语句块;
...
else
语句块;
end if;
举例:输入一个员工编号,给该员工涨奖金。策略是这样的:
如果原来员工没有奖金,则把基本工资的百分之10作为奖金,如果原来员工的奖金低于1000,把奖金提升到
1000,其他情况奖金提升百分之10。

  1. declare
  2. -- 声明奖金的变量
  3. v_comm emp.comm%type;
  4. begin
  5. -- 查询出员工的奖金
  6. select comm into v_comm from emp where empno=&no;
  7. -- 判断如果员工没有奖金,把基本工资的百分之10作为奖金
  8. if v_comm is null then
  9. update emp set comm=sal*0.1 where empno=&no;
  10. --如果原先奖金低于1000,提升到1000
  11. elsif v_comm<1000 then
  12. update emp set comm=1000 where empno=&no;
  13. -- 其他情况把奖金提升百分之10
  14. else
  15. update emp set comm=comm*1.1 where empno=&no;
  16. end if;

二.case when

case when 和java中switch语句比较像。
java中switch:
switch(变量名){
case 变量值1 :

语句块;
break;
case 变量值2 :
语句块;
break;
.....
default:
语句块;
}
case when 语法:
case 变量名
when 变量值1 then
语句块;
when 变量值2 then
语句块;
........
else:
语句块;
end case;
举例:根据用户输入的部门编号,输出不同的部门名称,要求使用case when实现,不查询dept表

  1. declare
  2. -- 声明部门编号的变量
  3. v_deptno emp.deptno%type:=&no;
  4. begin
  5. case v_deptno
  6. when 10 then
  7. dbms_output.put_line('技术部');
  8. when 20 then
  9. dbms_output.put_line('销售部');
  10. when 30 then
  11. dbms_output.put_line('公关部');
  12. when 40 then
  13. dbms_output.put_line('开发部');
  14. -- 其他情况
  15. else
  16. dbms_output.put_line('您要查找的部门不存在');
  17. end case;
  18. end;

if else 都能把case when 替代。case when 也可以替代if else.
语法:
case
when 条件表达式1 then
语句块;
when 条件表达式2 then
语句块;
....
else
语句块;
end case;
举例:

  1. declare
  2. -- 声明奖金的变量
  3. v_comm emp.comm%type;
  4. begin
  5. -- 查询出员工的奖金
  6. select comm into v_comm from emp where empno=&no;
  7. -- 判断如果员工没有奖金,把基本工资的百分之10作为奖金
  8. case
  9. when v_comm is null then
  10. update emp set comm=sal*0.1 where empno=&no;
  11. --如果原先奖金低于1000,提升到1000
  12. when v_comm<1000 then
  13. update emp set comm=1000 where empno=&no;
  14. -- 其他情况把奖金提升百分之10
  15. else
  16. update emp set comm=comm*1.1 where empno=&no;
  17. end case;
  18. end;

Oracle条件判断的更多相关文章

  1. Oracle 条件判断函数decode和case when then案例

    --decode条件判断函数 ,,,,,) from dual --需求:不通过连表查询,显示业主类型名称列的值 ,,,'商业','其他') from t_owners --case when the ...

  2. Oracle条件判断if...elsif

  3. Oracle条件判断列数量非where

    sum(case when typename='测试' then 1 else 0 end)

  4. oracle触发器加条件判断

    oracle触发器加条件判断,如果某个字段,isnode=0,那么不执行下面的方法,数据如下: create or replace trigger tr_basestation_insert_emp ...

  5. Oracle IF-ELSE 条件判断结构

    1. IF 语法 IF 表达式 THEN ... END IF; 例如: set serverout on declare v_name varchar2(20):='&name'; begi ...

  6. Oracle IF-ELSE条件判断结构

    关于条件判断的几个函数: 一.IF-ELSE 判断语句1.IF 语法 IF 表达式 THEN ... END IF; 输入账号名 kiki 以登陆账号 declare v_name ):='& ...

  7. C# if中连续几个条件判断

    C# if中连续几个条件判断 1.if (条件表达式1 && 条件表达式2) 当条件表达式1为true时 using System; using System.Collections. ...

  8. js条件判断时隐式类型转换

    Javascript 中,数字 0 为假,非0 均为真 在条件判断运算 == 中的转换规则是这样的: 如果比较的两者中有布尔值(Boolean),会把 Boolean 先转换为对应的 Number,即 ...

  9. 5-3 bash脚本编程之二 条件判断

    1. 条件测试的表达式 1. [ expression ]  :注意这个中括号的前后都有一个空格 2. [[ expression ]] 3. test expression 2.条件判断的类型 1. ...

随机推荐

  1. Java课程设计之——爬虫篇

    主要使用的技术 Httplcient Jsoup 多线程 dao模式 网络爬虫简介 网络爬虫(又称为网页蜘蛛,网络机器人,在FOAF社区中间,更经常的称为网页追逐者),是一种按照一定的规则,自动地抓取 ...

  2. 用Jenkins集成ios项目设置多scheme,同一代码自动输出多个环境包 实现便捷切换API环境

    Jenkins 安装使用参考我的博客http://www.cnblogs.com/zhujin/p/9064820.html Xcode 配置:说明 一个schema 对应一套环境(如生产,测试),一 ...

  3. Linux U盘启动盘制作工具

    近期由于自己使用的ubuntu系统一直出问题,想做一下启动盘帮助恢复系统和故障检测,以前一直是用ultraiso来进行写盘的,但是发现制作了几次后,失败的机率很高,主要有以下几种情况: 1.引导有问题 ...

  4. animation-play-state 在 ios 中不生效的解决办法(JS篇)

    我们要实现动画的播放和暂停,animation-play-state 在安卓端可以使用,但是在 ios 中不起作用,这时可以使用 js 来实现相同效果. 原理 通过 js 获取当前元素的 transf ...

  5. unity使用Animator做一个简单的动画

    1.在unity的物体上添加Animator组件 2.在Project下的Assets下添加Animator Controller 3.在Animator Controller添加动作 4.在动作之间 ...

  6. 中国剩余定理(CRT)

    只看懂了CRT,EXCRT待补.... 心得:记不得这是第几次翻CRT了,每次都有迷迷糊糊的.. 中国剩余定理用来求解类似这样的方程组: 求解的过程中用到了同余方程. x=a1( mod x1) x= ...

  7. H - Knight Moves DFS

    A friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the sh ...

  8. 掷骰子 dp

    B. 掷骰子 单点时限: 2.0 sec 内存限制: 512 MB 骰子,中国传统民间娱乐用来投掷的博具,早在战国时期就已经被发明. 现在给你 n 个骰子,求 n 个骰子掷出点数之和为 a 的概率是多 ...

  9. CodeForces - 913C (贪心)

    点完菜,他们发现好像觉得少了点什么? 想想马上就要回老家了某不愿透露姓名的林姓学长再次却陷入了沉思......... 他默默的去前台打算点几瓶二锅头. 他发现菜单上有n 种不同毫升的酒. 第 i 种有 ...

  10. 性能测试-pidstat 问题定位分析

    pidstat 概述 pidstat是sysstat工具的一个命令,用于监控全部或指定进程的cpu.内存.线程.设备IO等系统资源的占用情况.pidstat首次运行时显示自系统启动开始的各项统计信息, ...