使用CHECK在现有表上添加约束

时间:2014-12-16 03:23:45

标签: sql database oracle

任何人都可以查看我的SQL语句并告诉我它有什么问题。当我尝试在现有表上添加新约束时,我不断收到错误。

Error report:
SQL Error: ORA-01735: invalid ALTER TABLE option
01735. 00000 -  "invalid ALTER TABLE option"
*Cause:    
*Action:

2 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:3)

为检查约束添加一个括号。

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