因此,我需要一個約束來防止用戶輸入季度的第一天和季度的最後一天以外的日/月,以及日期該表將被「鎖定」以進行編輯。我在網上做了一些搜索,並認爲我找到了答案,但是當我嘗試時,我得到了一個錯誤。僅在Oracle SQL中檢查日期和月份的約束條件
alter table TABLE_NAME
add constraint data_beg_dt_chk check
(trunc(data_beg_dt, 'DD-MON') = (trunc(to_date('01-JAN', 'DD-MON'))||(trunc(sysdate, 'YYYY')))
OR trunc(data_beg_dt, 'DD-MON') = (trunc(to_date('01-APR', 'DD-MON'))||(trunc(sysdate, 'YYYY')))
OR trunc(data_beg_dt, 'DD-MON') = (trunc(to_date('01-JUL', 'DD-MON'))||(trunc(sysdate, 'YYYY')))
OR trunc(data_beg_dt, 'DD-MON') = (trunc(to_date('01-OCT', 'DD-MON'))||(trunc(sysdate, 'YYYY'))));
我得到的錯誤:
SQL Error: ORA-02436: date or system variable wrongly specified in CHECK constraint
02436. 00000 - "date or system variable wrongly specified in CHECK constraint"
*Cause: An attempt was made to use a date constant or system variable,
such as USER, in a check constraint that was not completely
specified in a CREATE TABLE or ALTER TABLE statement. For
example, a date was specified without the century.
*Action: Completely specify the date constant or system variable.
Setting the event 10149 allows constraints like "a1 > '10-MAY-96'",
which a bug permitted to be created before version 8.
有誰知道另一種方式,我可以只使用一天,一個月,但同時保持本年度用戶已enetered?
感謝
非常感謝約翰 - 那就是訣竅。 – patkipper