ORA 02436 sysdate oracle
这是网上能够搜索到的比较可信的结果:
Unfortunately you can't use SYSDATE in a check constraint as it is a dynamic Oracle variable. A better way to enforce this constraint would be to use a trigger. For example:

CREATE OR REPLACE TRIGGER trg_emp_dob BEFORE INSERT OR UPDATE ON emp
BEGIN
   IF :new.dob > SYSDATE THEN
      RAISE_APPLICATION_ERROR (num => -20000, msg => 'DOB Cannot be in the future');
   END IF;
END;

不过嘿嘿,我可不信邪,万事问大哥啊,于是在asktom上找到了这个解决方案:
Just create an additional column using as default SYSDATE. Then you can use this column to compare.
And if you want to hide this column create a view around it...

SQL> create table t
  2  (x   date,
  3   y   date default sysdate,
  4   constraint x_y check
  5   (
  6      x >= y
  7   )
  8  );

Table created.

SQL>
SQL> create view v as select x from t;

View created.

SQL>
SQL> insert into v values (sysdate);

1 row created.

SQL>
SQL> commit;

Commit complete.

SQL>
SQL> insert into v values (sysdate-1);
insert into v values (sysdate-1)
*
ERROR at line 1:
ORA-02290: check constraint (ADBM.X_Y) violated

总之oracle不能非常漂亮的解决这个问题,这里两个方案你看着选吧。

 
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/fenixshadow/article/details/1799192
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

ORA 02436 sysdate oracle

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭