2012-05-22 121 views
-1

試圖讓甲骨文獲得一個約會只將其設置爲一年,並比較手 之前插入或更新到我的數據庫中的值這是我到目前爲止已經試過。但我似乎被卡住 任何幫助將是巨大的,謝謝ORACLE SQL比較年份範圍觸發

create or replace 
TRIGGER CHECK_YEAR_DIFF 
BEFORE INSERT OR UPDATE OF YEAROFPERSON ON PERSON 
FOR EACH ROW 

Currentdate Date; 
Playeryrborn_Var Integer; 

Begin 

Currentdate := TRUNC(Sysdate,'YYYY'); 
YEAROFPERSON_var := new.YEAROFPERSON; 

    IF (currentDate - YEAROFPERSON_var <= 40) AND (currentDate - YEAROFPERSON_var => 16) THEN 

    dbms_Output.Put_Line('Year of Birth Updated Successfully'); 

    ELSE 

    dbms_output.put_line('Year of Birth Failed to Successfully Update'); 

    END IF; 

END; 
+1

什麼問題? – kmkaplan

+0

它似乎沒有工作。我不知道在哪裏出了問題:S –

+1

@MattLaw:「似乎沒有工作」是不是很描述。 – Quassnoi

回答

0

IF(currentDate - YEAROFPERSON_var < = 40)AND(currentDate - YEAROFPERSON_var => 16)

替換爲以下

IF(的currentdate - YEAROFPERSON_var < = 40)AND(的currentdate - YEAROFPERSON_var> = 16)

+0

乾杯@Sribharath雷迪Peketi –

0

我認爲你需要更改線路: 的currentdate - YEAROFPERSON_var < = 40

要:

cast(to_char(sysdate, 'YYYY') as int) - YearOfPerson_Var <= 40 
+0

非常感謝!只需要修復我的第二個條件,它會很甜蜜! –

+0

使用'提取物(一年SYSDATE)'會更容易一點,我認爲 –