我的Oracle 10gr2检查约束有什么问题?(What is wrong with my Oracle 10gr2 check constraint? Trying to enforce a da

编程入门 行业动态 更新时间:2024-10-28 06:28:24
我的Oracle 10gr2检查约束有什么问题?(What is wrong with my Oracle 10gr2 check constraint? Trying to enforce a date range)

我希望在日期范围内强制执行CHECK约束,以使列BIRTH_DATE中的所有日期都小于明天,并且大于或等于100年前。 我在CHECK约束中尝试了这个表达式:

BIRTH_DATE >= (sysdate - numtoyminterval(100, 'YEAR')) AND BIRTH_DATE < sysdate + 1

但是我收到错误“ORA-02436:在CHECK约束中错误指定的日期或系统变量”

有没有办法使用CHECK约束而不是触发器来完成此操作?

I want to enforce CHECK constraint on a date range such that all dates in column BIRTH_DATE are less than tomorrow and greater than or equal to 100 years ago. I tried this expression in a CHECK constraint:

BIRTH_DATE >= (sysdate - numtoyminterval(100, 'YEAR')) AND BIRTH_DATE < sysdate + 1

But I received the error "ORA-02436: date or system variable wrongly specified in CHECK constraint"

Is there a way to accomplish this using a CHECK constraint instead of a trigger?

最满意答案

检查约束表达式必须是确定性的,所以这种滑动日期范围在检查约束中不可强制执行。 从SQL参考

检查约束条件不能包含以下结构:

* Subqueries and scalar subquery expressions * Calls to the functions that are not deterministic (CURRENT_DATE,

CURRENT_TIMESTAMP,DBTIMEZONE,LOCALTIMESTAMP,SESSIONTIMEZONE,SYSDATE,SYSTIMESTAMP,UID,USER和USERENV)

A check constraint expression has to be deterministic, so this sort of sliding date range is not enforcable in a check constraint. From the SQL Reference

Conditions of check constraints cannot contain the following constructs:

* Subqueries and scalar subquery expressions * Calls to the functions that are not deterministic (CURRENT_DATE,

CURRENT_TIMESTAMP, DBTIMEZONE, LOCALTIMESTAMP, SESSIONTIMEZONE, SYSDATE, SYSTIMESTAMP, UID, USER, and USERENV)

更多推荐

本文发布于:2023-08-05 10:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1431266.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么   wrong   Oracle   date   range

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!