mikhl 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 Quote Link to comment https://forums.phpfreaks.com/topic/227208-check-constraint-sql/ Share on other sites More sharing options...
gizmola 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. Quote Link to comment https://forums.phpfreaks.com/topic/227208-check-constraint-sql/#findComment-1172658 Share on other sites More sharing options...
mikhl 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 Quote Link to comment https://forums.phpfreaks.com/topic/227208-check-constraint-sql/#findComment-1172781 Share on other sites More sharing options...
gizmola 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. Quote Link to comment https://forums.phpfreaks.com/topic/227208-check-constraint-sql/#findComment-1172892 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.