Toon posts:

[Oracle SQL] check constraint plaatsen op geboortedatum

Pagina: 1
Acties:
  • 156 views sinds 30-01-2008
  • Reageer

Verwijderd

Topicstarter
Ik probeer een check constraint te plaatsen op een geboortedatum in een Oracle Database. Ik moet gewoon stomweg nakijken of de geboortedatum die ingevoerd wordt ook effectief voor de systeemdatum valt. Ik heb al vanalles geprobeerd, maar ik krijg iedere keer de melding: "ORA-02436: Datum- of systeemvariabele is onjuist opgegeven in CHECK-beperking."
De datum staat in het standaard formaat 'DD-MON-YYYY'.
Ik had eerst gedacht dat het gewoon "check (gebdatum <= sysdate)" moest zijn.
Dat lukt dus niet. De dingen afronden met een "trunc" lukt dus ook niet.
Kan iemand mij hiermee helpen?

Bedankt.

  • whoami
  • Registratie: December 2000
  • Laatst online: 14:31
Kan je een dergelijke constraint met een CHECK constraint definieren, of moet je dat niet in een TRIGGER doen?

https://fgheysels.github.io/


Verwijderd

Topicstarter
Dit zou in een constraint moeten gebeuren ja. Het zou makkelijker zijn om dit in een trigger te doen, maar dat kan ik hier spijtig genoeg niet.

Verwijderd

check(to_date(gebdatum,'dd-mon-yyyy') <= trunc(sysdate))
of
check(to_date(gebdatum,'dd-mon-rrrr') <= trunc(sysdate))

[ Voor 44% gewijzigd door Verwijderd op 07-01-2004 12:20 ]


Verwijderd

Topicstarter
Dit had ik dus ook geprobeerd, maar hij blijft hier dezelfde fout op geven, en ik zie niet echt in wat hier fout aan is... :'(
En of een to_date echt nodig is betwijfel ik, want gebdatum is van het type "date".
Maar ik heb het toch ook maar geprobeerd...

[ Voor 36% gewijzigd door Verwijderd op 07-01-2004 12:26 ]


  • Swa-baldie
  • Registratie: Juni 2002
  • Laatst online: 19-06-2023
Van metalink.oracle.com (kun je gratis account aanmaken als ik me niet vergis)

Doc ID: Note:102614.1
Subject: SQL: ORA-02438 or ORA-02436 executing ADD CONSTRAINT clause
Type: BULLETIN
Status: PUBLISHED
Content Type: TEXT/PLAIN
Creation Date: 16-MAR-2000
Last Revision Date: 10-MAY-2001


Problem Description
===================
You are attempting to add a constraint to an existing table and are recieving one of the following errors: ORA-02438: Column check constraint cannot reference other columns or ORA-02436: date or system variable wrongly specified in CHECK constraint
Solution Description
====================
Default constraint names and implicit conversion are no longer permitted in constraint clauses.
Explanation
===========
Specifying a constraint without a name will result in the following:
alter table emp add constraint check (hiredate > '01-JAN-2010');
ORA-02438: Column check constraint cannot reference other columns When we specify the constaint name we then obtain the following: alter table emp add constraint check_hiredate check (hiredate > '01-JAN-2010'); ORA-02436: date or system variable wrongly specified in CHECK constraint This will occur so long as we rely on the implicit string to date conversion in the CHECK clause: alter table emp add constraint check_hiredate check (hiredate > to_date('01-JAN-2010')); ORA-02436: date or system variable wrongly specified in CHECK constraint Removing the implicit conversion and replacing it with and implicit conversion allows the constraint to succeed: alter table emp add constraint check_hiredate check (hiredate > to_date('01-JAN-2010','DD-MON-YYYY')); ORA-02293: cannot validate (SCOTT.CHECK_HIREDATE) - check constraint violated Note: It fails on purpose in this example so that we can show that the condition is being evaluated and we could simply change the year to 1960 to actually add the constraint.
References
==========
[BUG:659021] ORA-2438 AND ORA-2436 ADDING CHECK CONSTRAINT ON A DATE FIELD TO A TABLE
Search Words
============
ORA-2438 ORA-2436 ORA-2293

Verwijderd

Wat is het standaard date formaat van de DB ? Daarmee bedoel ik dus niet het display formaat wat jij normaliter ziet maar het interne formaat van de DB (nls_date_format in orainit). Vaak vind je dd-mon-rr in deze parameter.
Dat formaat moet je aanhouden.

Verwijderd

Topicstarter
Dit formaat is aangehouden. "DD-MON-YYYY"

Verwijderd

Topicstarter
Indien dit niet mogelijk is met een gewone constraint, is er dan misschien iemand die weet hoe ik dit met trigger zou kunnen oplossen?

  • whoami
  • Registratie: December 2000
  • Laatst online: 14:31
Verwijderd schreef op 07 januari 2004 @ 13:09:
Indien dit niet mogelijk is met een gewone constraint, is er dan misschien iemand die weet hoe ik dit met trigger zou kunnen oplossen?
Gewoon een trigger maken op die tabel dus, en gewoon checken.

code:
1
2
3
4
select sysdate INTO :currDate FROM dual;

if blaat > currDate then
end if;

https://fgheysels.github.io/

Pagina: 1