2017-05-15 3 views
0

この機能に関するヘルプが必要です。コードにはエラーはありませんが、2番目の条件/文の値と同じ結果が返され続けます。PL SQL Retirement function

これは、次のように動作すると考えられます。 従業員の雇用日(DOFA)が25歳以下の場合、雇用日は雇用日から35歳です。それ以外の場合、退職日は従業員の年齢が6

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; 
+0

DOFAとDOBは日付型ですから、それらから年を抽出して減算する必要があります。年は「EXTRACT(YEAR FROM DOFA)」で抽出できます –

+0

ありがとうございました。 – Auwal

答えて

1

です。条件によって、ある日付から別の日付が減算されます。これにより、年数ではなく、2つの間の日の間にが与えられます。

months_between()は、2つの日付間の月数を示します。 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;