You have a trailing comma right at the end, and one too many closing brackets:
...84))),);
Unless you've cut something out before posting, which may be the case as the error references line 23 (but hopefully not as it's tricky to see a problem in code you can't see at all). What you have compiles if that becomes:
...84)));
But the condition is wrong anyway, as others have pointed out. One way of getting the result I think you want is:
...
CONSTRAINT IC4 CHECK (classification != 'junior' OR hours BETWEEN 55 AND 84)
);
The OR
means that the hours
check is only applied when the classification
is 'junior'
, and any other classification
is not restricted. (If you need different rules for different classifications, have a look at the very similar question Chris Saxon linked to in comments).
With some test data:
insert into students values (1, 'A', 'junior', 54, 1, 1); -- ORA-02290
insert into students values (2, 'B', 'junior', 55, 1, 1); -- OK
insert into students values (3, 'C', 'junior', 84, 1, 1); -- OK
insert into students values (4, 'D', 'junior', 85, 1, 1); -- ORA-02290
insert into students values (5, 'E', 'senior', 54, 1, 1); -- OK
insert into students values (6, 'F', 'senior', 55, 1, 1); -- OK
insert into students values (7, 'G', 'senior', 84, 1, 1); -- OK
insert into students values (8, 'H', 'senior', 85, 1, 1); -- OK
select * from students order by id;
ID NAME CLASSIFICATION HOURS GPA MENTOR
---- ---------- -------------- ----- --- ------
2 B junior 55 1.00 1
3 C junior 84 1.00 1
5 E senior 54 1.00 1
6 F senior 55 1.00 1
7 G senior 84 1.00 1
8 H senior 85 1.00 1
6 rows selected
BETWEEN
is inclusive, so this is the same as:
CONSTRAINT IC4 CHECK (classification != 'junior' OR (hours >= 55 AND hours <= 84))
You might also want a check constraint on classification
, particularly as this constraint is case-sensitive as it stands; or preferably have a separate classification
table and have a foreign key constraint on the column in this table. But that's probably out of your control for this assignment.