简体   繁体   English

未来日期SQL Developer

[英]Future Dates SQL Developer

I'm trying to create a constraint that does not allow dates in future years. 我正在尝试创建一个不允许将来年份使用的约束。 I have this: 我有这个:

ALTER TABLE PACIENTE ADD CONSTRAINT ck_FechaNacimiento
CHECK (FechaNacimiento<=current_date);

But i'm getting error 02436 . 但是我收到error 02436

You cannot create a non-deterministic constraint. 您不能创建非确定性约束。 So you cannot create a constraint that references a function like current_date or sysdate that returns a different value every time you call it. 因此,您不能创建引用诸如current_datesysdate类的函数的约束,该约束每次调用时都会返回不同的值。

If you want to enforce this sort of thing, you'd need to create a trigger on the table that throws an error if the business rule is violated, ie 如果要强制执行此类操作,则需要在表上创建一个触发器,如果​​违反了业务规则,该触发器将引发错误,即

CREATE OR REPLACE TRIGGER trg_paciente
  BEFORE INSERT OR UPDATE 
  ON paciente
  FOR EACH ROW
BEGIN
  IF( :new.FechaNacimiento > current_date )
  THEN
    RAISE_APPLICATION_ERROR( -20001, 'FechaNacimiento<=current_date must be in the past' );
  END IF;
END;

I'd tried again with this and didn't show error, thanks by the way: 我再次尝试过此操作,但未显示错误,谢谢:

ALTER TABLE EXAMENPACIENTE ADD CONSTRAINT ExamenPaciente_FechaExamen_c1 CHECK (FechaExamen<='30-SEP-2013'); ALTER TABLE EXAMENPACIENTE ADD CONSTRAINT ExamenPaciente_FechaExamen_c1 CHECK(FechaExamen <='30-SEP-2013');

ALTER TABLE PACIENTE ADD CONSTRAINT ck_FechaNacimiento CHECK (FechaNacimiento<=SYSDATE);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM