在Oracle中,用户输入一个雇员编号,根据它所在的部门给调整工资,规则:10部门上涨20%,20部门降薪10%,30上涨30%,要求最高不能超过5000,最低不能低于750,如果超过5000就停留在

用户输入一个雇员编号,根据它所在的部门给调整工资,规则:

10部门上涨20%,20部门降薪10%,30上涨30%,要求最高不能超过5000,最低不能低于750,如果超过5000就停留在5000,低于750就停留在750。

代码如下:

第一种:

--用户输入一个雇员编号,根据它所在的部门给调整工资,规则:10部门上涨20%,20部门降薪10%,30上涨30%,要求最高不能超过5000,最低不能低于750,如果超过5000就停留在5000,低于750就停留在750。
set serveroutput on
declare
--定义变量
  v_eno EMP_TEMP.EMPNO%type;
  v_sal EMP_TEMP.sal%type;
  v_firstSal EMP_TEMP.sal%type;
  v_dept EMP_TEMP.deptno%type;
begin
--手动输入指定eno
  v_eno :=&empno;
  --获取最初工资
  select sal into v_firstSal from emp_temp where empno=v_eno;
  --获取部门编号
  select deptno into v_dept
  from emp_temp
  where empno=v_eno;
--如果部门编号是10,对其进行更新操作
  if v_dept =10 then
    update emp_temp
    set sal =sal*1.2
    where deptno =10;
--如果部门编号是20,对其进行更新操作
  elsif v_dept =20 then
    update emp_temp
    set sal =sal*0.9
    where deptno =20;
--如果部门编号是30,对其进行更新操作
  elsif v_dept =30 then
    update emp_temp
    set sal =sal*1.3
    where deptno =30;
  end if;
  select deptno into v_dept from emp_temp where empno=v_eno;
  select max(sal)into v_sal from emp_temp where deptno=v_dept;
  loop
--如果超过5000就停留在5000;
  if v_sal>5000 then
    update emp_temp
    set sal =5000
    where sal =v_sal and deptno =v_dept;
  end if;
  select max(sal) into v_sal from emp_temp where deptno=v_dept;
  exit when v_sal<=5000;
  end loop;
  select min(sal) into v_sal from emp_temp where deptno=v_dept;
  loop
--低于750就停留在750;
  if v_sal<750 then
    update emp_temp
    set sal=750
    where sal =v_sal and deptno=v_dept;
  end if;
  select min(sal) into v_sal from emp_temp where deptno=v_dept;
  exit when v_sal>=750;
  end loop;
  dbms_output.put_line('编号为'||v_eno||'  部门为'||v_dept||'  刚开始工资为'||v_firstSal||'  变化后的工资为'||v_sal);
--错误提示
exception
    when no_data_found then
      dbms_output.put_line('查无此人!');
end;
/
  

运行结果截图:

第二种:

--用户输入一个雇员编号,根据它所在的部门给调整工资,规则:10部门上涨20%,20部门降薪10%,30上涨30%,要求最高不能超过5000,最低不能低于750,如果超过5000就停留在5000,低于750就停留在750。
set serveroutput on
declare
--定义变量
  v_eno EMP_TEMP.EMPNO%type;
  v_sal EMP_TEMP.sal%type;
  v_firstSal EMP_TEMP.sal%type;
  v_dept EMP_TEMP.deptno%type;
begin
--手动输入指定eno
  v_eno :=&empno;
  --获取最初工资
  select sal,sal into v_firstSal,v_sal from emp_temp where empno=v_eno;
  --获取部门编号
  select deptno into v_dept
  from emp_temp
  where empno=v_eno;
--如果部门编号是10,对其进行更新操作
  if v_dept =10 then
   v_sal:=v_sal*1.2;
   
    if v_sal>5000 then
      v_sal:=5000;
    end if;
    if v_sal<750 then
      v_sal:=750;
    end if;
    
--如果部门编号是20,对其进行更新操作
  elsif v_dept =20 then
    v_sal:=v_sal*0.9;
    
    if v_sal>5000 then
      v_sal:=5000;
    end if;
    if v_sal<750 then
      v_sal:=750;
    end if;
    
--如果部门编号是30,对其进行更新操作
  elsif v_dept =30 then
    v_sal:=v_sal*1.3;
    
    if v_sal>5000 then
      v_sal:=5000;
    end if;
    if v_sal<750 then
      v_sal:=750;
    end if;
    
  end if;
  dbms_output.put_line('编号为'||v_eno||'  部门为'||v_dept||'  刚开始工资为'||v_firstSal||'  变化后的工资为'||v_sal);
--错误提示
exception
    when no_data_found then
      dbms_output.put_line('查无此人!');
end;
/
  

 运行结果截图:

 当输入的编号不存在,则执行exception报错部分。

 

  • 2
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序yan

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值