declare cursor cur is select a.empno,a.sal,a.hiredate from emp a,emp b where a.mgr = b.empno; cc cur%rowtype; begin for cc in cur loop if (to_date(to_char(cc.hiredate,'yyyy-mm'),'yyyy-mm') - to_date(to_char('1981-06','yyyy-mm'),'yyyy-mm'))<30 then update emp set sal= sal*1.1 where empno = cc.empno; else
update emp set sal = sal * 1.05 where empno = cc.empno; end if; end loop; end;
日期相减返回来是天的单位,你不用把一个日期转成字符再转回来日期的: if (to_date(to_char(cc.hiredate,'yyyy-mm'),'yyyy-mm') - to_date(to_char('1981-06','yyyy-mm'),'yyyy-mm'))<30 then update emp set sal= sal*1.1 where empno = cc.empno; else 把上述语句改成: if cc.hiredate - to_date('1981-06','yyyy-mm')<30 then update emp set sal= sal*1.1 where empno = cc.empno; else