Database Administration (MOSC)

MOSC Banner

Validate a field with a check contraint using regular expression does not work

edited Apr 22, 2021 12:49PM in Database Administration (MOSC)

So I created the following CONSTRAINT check for the field:

ALTER TABLE CERTIFICAT ADD

(

 CONSTRAINT chk_cervcdmotifmodifcertf CHECK 

    (REGEXP_LIKE(cervcdmotifmodifcertf ,'^[0[1-9][0-9]|[1-2][0-9][0-9]|30[0-3]|400$'))

);

So, if I get a value like "000", it's not supposed to be OK. The check constraint validate it and must send an error message. But, if I try it ...

SQL> alter session set current_schema=AGRMDHD1;

Session modifiée.

SQL> update certificat

 2   set cervcdmotifmodifcertf = '000'

 3 where pkcer= 340893;

1 ligne mise à jour.

SQL>

The check constraint of the table validate it and it's not an error. Why ? What I do wrong ?

I also try another thing. I dropped the check constraint and tried manage the check in a trigger for the table.

Howdy, Stranger!

Log In

To view full details, sign in to My Oracle Support Community.

Register

Don't have a My Oracle Support Community account? Click here to get started.

Category Leaderboard

Top contributors this month

New to My Oracle Support Community? Visit our Welcome Center

MOSC Help Center