简体   繁体   中英

Adding constraint on an existing table with CHECK

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:

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)
              );

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)
           );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM