Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: refer to SYSDATE function in a CHECK constraint--doable?

Re: refer to SYSDATE function in a CHECK constraint--doable?

From: Ora NT DBA <orantdba_at_netscape.net>
Date: Thu, 21 Mar 2002 20:08:21 -0800
Message-ID: <F001.004307A7.20020321200821@fatcity.com>


HI Roy,

As you have already figured out sysdate cannot be used in a constraint.

John

roy.e.pardee_at_lmco.com wrote:

>Greetings all,
>
>I've got a table with a date field on a 8.1.6.0 db. I'd like to constrain
>the values entered into this field to be less than or equal to the date on
>which the record was entered. I figured a table-level check constraint
>would serve & so I ran:
>
>ALTER TABLE TLB_COPIES
> ADD (CONSTRAINT TLBCPY_DATE_LAST_LABEL_CK CHECK (DATE_LAST_LABEL <=
>SYSDATE)
> EXCEPTIONS INTO COMN_EXCEPTIONS)
>
>And Oracle complained thus:
>
> ADD (CONSTRAINT TLBCPY_DATE_LAST_LABEL_CK CHECK (DATE_LAST_LABEL <=
>SYSDATE)
> *
>ERROR at line 2:
>ORA-02436: date or system variable wrongly specified in CHECK constraint
>
>I've also tried using TO_DATE(SYSDATE) after running accross that expression
>in some code examples in the docs (does SYSDATE not return a date type?),
>but get the same error.
>
>I've searched through metalink for this error, but everything I've found
>deals with how you've got to to_date() a date literal (e.g., no implicit
>conversions) and be sure to use a full four-digit year (as of 8.x I think).
>But I'm not seeing anything that refers to the sysdate function--is it just
>not allowed? I'm pretty sure you can use it as a DEFAULT...
>
>Thanks!
>
>-Roy
>
>Roy Pardee
>Programmer/Analyst
>SWFPAC Lockheed Martin IT
>Extension 8487
>

-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Ora NT DBA
  INET: orantdba_at_netscape.net

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
Received on Thu Mar 21 2002 - 22:08:21 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US