表结构如下:
employee 表名
empno varchar2(5) PK 员工编号
ename varchar2(25)   员工姓名
designation varchar2(20)  职务
dateofjoining date 加入公司的时间
branchcode varchar2(25)   分部门编号
deptcode varchar2(15)部门编号salary_records 表名
empcode varchar2(10) 员工编号
working_days number
empsal number 收入要求:用条件控制语句实现:
如果部门代码为“DP01”,奖金为2000
如果部门代码为“DP02”,奖金为1700
如果部门代码为“DP03”,奖金为1500
根据职员所在的部门代码,来更新职工的工资记录我的思路是先定义一个变量,把employee查询出来部门编号赋给变量,然后再更新。但我无法实现。请高手帮忙。
我写的如下:
set serveroutput on
declare
chaxun SCOTT.EMPLOYEE%rowtype;
begin
select deptcode into chaxun from scott.employee
where empno in (select empcode from scott.salary_records)
if chaxun='DP01' then update scott.salary_records
set empsal=(select empsal+2000 from SCOTT.SALARY_RECOESS,SCOTT.EMPLOYEE where SALARY_RECORDS.empcode=EMPLOYEE.empno );
end if;
if chaxun='DP02' then update scott.salary_records
set empsal=(select empsal+1700 from SCOTT.SALARY_RECOESS,SCOTT.EMPLOYEE where SALARY_RECORDS.empcode=EMPLOYEE.empno );
end if;
if chaxun='DP03' then update scott.salary_records
set empsal=(select empsal+1500 from SCOTT.SALARY_RECOESS,SCOTT.EMPLOYEE where SALARY_RECORDS.empcode=EMPLOYEE.empno );
end if;
commit;
end;