9人参与 • 2025-06-09 • Oracle
if 条件1 then 执行的逻辑1; elsif 条件2 then --条件1不满足的时候,会先判断是否满足条件2 执行的逻辑2; else ---条件1 和条件2 都不满足 执行的逻辑3; end if; ---结束 if else 条件判断
传入一个员工的编号
如果这个员工的工资小于1000,就给他加300奖金
如果这个员工的工资 1000 到 2000,就给他加200奖金
如果这个员工的工资 大于 2000,就给他加100奖金
select * from emp where empno=7788;
declare v_empno number := &input; v_sal number; begin select sal into v_sal from emp where empno = v_empno; if v_sal < 1000 then update emp set comm = nvl(comm, 0) + 300 where empno = v_empno; -- commit; elsif v_sal between 1000 and 2000 then --条件1不满足的时候,会先判断是否满足条件2 update emp set comm = nvl(comm, 0) + 200 where empno = v_empno; -- commit; else ---条件1 和条件2 都不满足 update emp set comm = nvl(comm, 0) + 100 where empno = v_empno; end if; ---结束 if else 条件判断 -- commit; end; select * from emp where empno=7788;
示例:用户输入 员工编号,判断 这个员工所在部门的人数,如果3个以内,则不变,如果5个以内 则 该部门所有员工降薪100,否则 所有员工降薪200
declare v_empno emp.empno%type := &input; v_count number; begin select count(1) into v_count from emp where deptno in (select deptno from emp where empno = v_empno); if v_count < 3 then null; elsif v_count >= 3 and v_count < 5 then update emp set sal = sal - 100 where deptno in (select deptno from emp where empno = v_empno); -- commit; else update emp set sal = sal - 200 where deptno in (select deptno from emp where empno = v_empno); end if; -- commit; end;
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
您想发表意见!!点此发布评论
版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。
发表评论