一. if/else

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

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

declare
-- 声明奖金的变量
v_comm emp.comm%type;
begin
-- 查询出员工的奖金
select comm into v_comm from emp where empno=&no;
-- 判断如果员工没有奖金,把基本工资的百分之10作为奖金
if v_comm is null then
update emp set comm=sal*0.1 where empno=&no;
--如果原先奖金低于1000,提升到1000
elsif v_comm<1000 then
update emp set comm=1000 where empno=&no;
-- 其他情况把奖金提升百分之10
else
update emp set comm=comm*1.1 where empno=&no;
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表

declare
-- 声明部门编号的变量
v_deptno emp.deptno%type:=&no;
begin
case v_deptno
when 10 then
dbms_output.put_line('技术部');
when 20 then
dbms_output.put_line('销售部');
when 30 then
dbms_output.put_line('公关部');
when 40 then
dbms_output.put_line('开发部');
-- 其他情况
else
dbms_output.put_line('您要查找的部门不存在');
end case;
end;

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

declare
-- 声明奖金的变量
v_comm emp.comm%type;
begin
-- 查询出员工的奖金
select comm into v_comm from emp where empno=&no;
-- 判断如果员工没有奖金,把基本工资的百分之10作为奖金
case
when v_comm is null then
update emp set comm=sal*0.1 where empno=&no;
--如果原先奖金低于1000,提升到1000
when v_comm<1000 then
update emp set comm=1000 where empno=&no;
-- 其他情况把奖金提升百分之10
else
update emp set comm=comm*1.1 where empno=&no;
end case;
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. Linux常用命令02(远程管理)

    01 关机/重启 序号 命令 对应英文 作用 01 shutdown 选项 时间 shutdown 关机/重新启动 1.1 shutdown shutdown 命令可以 安全 关闭 或者 重新启动系统 ...

  2. SVG案例:动态去创建元素createElementNS

    案例一: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <titl ...

  3. 用网线连接Windows和Linux台式机,并实现Linux共享Windows的WiFi网络

    前言 由于工作需要,需要利用网线将自己的笔记本和Linux台式机进行连接,实现Windows可以远程登录Linux机器,并实现Linux共享Windows的WiFi网络. 网上的很多方法可以实现两台机 ...

  4. Charles抓包——弱网测试(客户端)

    基础知识 网络延迟:网络延时指一个数据包从用户的计算机发送到网站服务器,然后再立即从网站服务器返回用户计算机的来回时间.通常使用网络管理工具PING(Packet Internet Grope)来测量 ...

  5. 2. js的异步

    1. 回掉2. promise3. Generator4. Async/await

  6. cli命令速查

    在文件的指定行(n)插入指定内容: sed -i "niecho "haha"" a 执行后,在a文件的第n行插入echo "haha" 多 ...

  7. react: typescript project initialize

    Initialize the project create a folder project Now we’ll turn this folder into an npm package. npm i ...

  8. mybatis源码学习:一级缓存和二级缓存分析

    目录 零.一级缓存和二级缓存的流程 一级缓存总结 二级缓存总结 一.缓存接口Cache及其实现类 二.cache标签解析源码 三.CacheKey缓存项的key 四.二级缓存TransactionCa ...

  9. Java中什么是构造方法

    this(...)本类的构造方法super(...)父类的构造方法构造方法:给对象的数据进行初始化格式:A:方法名与类名相同B:没有返回值类型,连void都没有C:没有具体的返回值注意事项:A:如果我 ...

  10. 百度云虚拟空间(BCH)

    百度云虚拟空间(BCH)上的一些默认配置 :first-child { margin-top: 0;}blockquote > :last-child { margin-bottom: 0;}i ...