ORACLE SQL比较年份范围触发器

时间:2012-05-22 13:49:10

标签: sql database oracle triggers

尝试让Oracle获取日期,将其设置为仅年份,并与之前插入或更新到我的数据库中的值进行比较 这是我到目前为止所尝试的。但我似乎陷入困境 任何帮助都会很棒,谢谢

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;

2 个答案:

答案 0 :(得分:0)

我认为你需要改变这条线:     currentDate - YEAROFPERSON_var&lt; = 40

要:

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

答案 1 :(得分:0)

IF(currentDate - YEAROFPERSON_var&lt; = 40)AND(currentDate - YEAROFPERSON_var =&gt; 16)

替换为以下

IF(currentDate - YEAROFPERSON_var&lt; = 40)AND(currentDate - YEAROFPERSON_var&gt; = 16)