mikhl 0 Posted February 9, 2011 Share Posted February 9, 2011 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 post Share on other sites
gizmola 218 Posted February 11, 2011 Share Posted February 11, 2011 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. Link to post Share on other sites
mikhl 0 Posted February 11, 2011 Author Share Posted February 11, 2011 Thanks for your comment. I have figured out what I wanted: add constraint validclassid check(subjectid like 'COMP%' or subjectid like 'INFO%' or subjectid like 'SYS%') Sorry if I wasn't clear Link to post Share on other sites
gizmola 218 Posted February 11, 2011 Share Posted February 11, 2011 Thanks for reporting back your results. I didn't think that you could use LIKE in a check constraint, but then my Oracle skills are getting pretty rusty these days. Link to post Share on other sites
Recommended Posts
Archived
This topic is now archived and is closed to further replies.