0

Can anyone have a look at my SQL statement and tell me what is wrong with it. I keep getting error when I tried to add a new constraint on an existing table.

Error report:
SQL Error: ORA-01735: invalid ALTER TABLE option
01735. 00000 -  "invalid ALTER TABLE option"
*Cause:    
*Action:
1
  • 1
    Note: these expressions look suspiciously like regular expressions: [^A-L] - they will not work with the LIKE operator how you may think they will. You may need to use REGEXP_LIKE (and remove the %s). Commented Dec 16, 2014 at 6:31

2 Answers 2

3

You need parentheses around the entire condition for check:

alter table seat 
    add constraint check_seats
        CHECK ((BLOCKNO = 'FRONT' AND ROWNO NOT LIKE '%[^A-J]%'  AND SEATNO <=40) OR 
               (BLOCKNO = 'MIDDLE' AND ROWNO NOT LIKE '%[^A-L]%' AND SEATNO <=50) OR
               (BLOCKNO = 'BACK' AND ROWNO NOT LIKE '%[^A-N]%' AND SEATNO <=60)
              );
Sign up to request clarification or add additional context in comments.

1 Comment

@NashTamu . . . It is unusual that you thanked me for this answer but chose the other answer. Of course, as the OP, you have the right to accept whichever answer you like.
3

Add one more parenthesis for the check constraint.

     CHECK ((BLOCKNO = 'FRONT' AND ROWNO NOT LIKE '%[^A-J]%'  AND SEATNO <=40) OR 
            (BLOCKNO = 'MIDDLE' AND ROWNO NOT LIKE '%[^A-L]%' AND SEATNO <=50) OR
            (BLOCKNO = 'BACK' AND ROWNO NOT LIKE '%[^A-N]%' AND SEATNO <=60)
           );

1 Comment

'%[^A-J]%' mixes regex and non-regex syntax. Consequently the NOT LIKE will always be true, regardless of the value of ROWNO.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.