Jump to content

Check Constraint SQL


mikhl

Recommended Posts

I want to create a check constraint that allows the input of data like 'COMP%' and 'SYS%' and 'INFO%'

 

The code that I have tried is as follows:

alter table subject
add constraint validclassid check(subjectid like 'COMP%', 'INFO%', 'SYS%');

and...

alter table subject
add constraint validclassid check(subjectid like 'COMP%' AND 'INFO%' AND 'SYS%');

and...

alter table subject
add constraint validclassid check(subjectid like 'COMP%' OR 'INFO%' OR 'SYS%');

 

None of the above are working, I could really use your help. Thanks.

 

I am using Oracle 10g

Link to comment
https://forums.phpfreaks.com/topic/227208-check-constraint-sql/
Share on other sites

A check constraint is like a little piece of validation code, that must evaluation to true or false.  It is not a query.  I'm not really sure what you're going for, but if you literally expect that the subjectid will be the strings 'COMP%' or 'INFO%', then you should have add ... check( subjectid in ('COMP%', 'INFO%', 'SYS%'))

 

If you literally are trying to get "LIKE" behavior so that you only allow words that start with COMP, INFO and SYS, but are actually COMPUTER, INFORMATION etc., then you might try using SUBSTR() to get the first 3 characters, although I don't know if that will work in a constraint.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.