Plsql PL SQL失效函数

Plsql PL SQL失效函数,plsql,date-arithmetic,Plsql,Date Arithmetic,我需要这个函数的帮助。代码没有错误,但它始终返回与第二个条件/语句的值相同的结果 这就是它的工作原理: 如果员工在雇佣日期的年龄DOFA小于或等于25,则退休日期为雇佣日期后35年。否则,退休日期为员工60岁 create or replace function EDOR_FUNCTION (DOFA in date, DOB in date) return date is new_edor_date date; begin if DOFA - D

我需要这个函数的帮助。代码没有错误,但它始终返回与第二个条件/语句的值相同的结果

这就是它的工作原理: 如果员工在雇佣日期的年龄DOFA小于或等于25,则退休日期为雇佣日期后35年。否则,退休日期为员工60岁

create or replace function EDOR_FUNCTION
    (DOFA in date, DOB in date) 
    return date
is
    new_edor_date date;

begin

  if 
      DOFA - DOB <= 25 then new_edor_date := add_months(DOFA,  35*12);
  else
      new_edor_date := add_months(DOB, 60*12);
  end if;

  return  new_edor_date;

end;

你的情况是从一个日期减去另一个日期。这给出了两者之间的天数,而不是年数

months\u between给出两个日期之间的月数。乘以12得到年数

if  months_between(DOFA , DOB) <= (25*12) then 
     new_edor_date := add_months(DOFA,  35*12);
else
     new_edor_date := add_months(DOB, 60*12);
end if;

DOFA和DOB是日期类型,您需要从中提取年份,然后减去。年可以提取提取每年从DOFAThank巴迪你是非常有帮助的充分。。。它起作用了