I want to apply a CHECK constraint to a date range so that all dates in the BIRTH_DATE column are less than tomorrow and greater than or equal to 100 years ago. I tried this expression in the CHECK constraint:
BIRTH_DATE >= (sysdate - numtoyminterval(100, 'YEAR')) AND BIRTH_DATE < sysdate + 1
But I got the error "ORA-02436: date or system variable incorrectly specified in the CHECK constraint"
Is there a way to accomplish this using a CHECK constraint instead of a trigger?
The expression for the check constraint must be deterministic, so this type of slip date range cannot be used in the check constraint. From SQL Reference
:* 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)
:
* 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)
, Oracle : TRUE, . 99- , (,) 2 , .
, , CREATED_DATE, SYSDATE, :
BIRTH_DATE >= (CREATED_DATE - numtoyminterval(100, 'YEAR')) AND BIRTH_DATE < CREATED_DATE + 1
, INSERT, API.
Source: https://habr.com/ru/post/1698322/More articles:Should the Cancel button be used as the Close button on a Windows form? - designHow to determine if the text is in Cyrillic? - unicodeSQL query that replaces null values. - nullStandard code refactoring on a large code base - c ++Как сериализовать DateTime с нулевым значением в веб-службе .net? - datetimeFirmware management in version control - version-controlSetting the Body OnLoad attribute on the MVC Asp.net home page - javascriptДва объекта домена в одном представлении - grailsSQL Server 2008 Geospatial Queries - sqlКак читать из порта ввода/вывода с памятью в .Net? - pointersAll Articles