oracle 数字或值错误 : 字符到数值的转换错误

来源:百度知道 编辑:UC知道 时间:2024/06/19 23:41:52
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;

另外
两个to_date 相减,返回的是天数吧,,如果我想查询哪些人是在1981年6月工作的,是让两个to_date相减=0还是<30(假设一个月30天)呢??

非常感谢您抽出时间帮我解答问题

日期相减返回来是天的单位,你不用把一个日期转成字符再转回来日期的:
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