这个删除查询有什么问题?

时间:2014-08-12 11:04:40

标签: sql oracle

DELETE CUSTSEGCONTROL.x FROM CUSTSEGCONTROL x, CUSTSEGCONTROL y 
WHERE x.custsegcontrolid < y.custsegcontrolid 
AND x.customerid = y.customerid 
AND tripid='A2G0G5' 
AND registrationstatus!=3;

我收到此错误消息。

Error starting at line 1 in command: DELETE x FROM CUSTSEGCONTROL x, CUSTSEGCONTROL y WHERE x.custsegcontrolid < y.custsegcontrolid AND x.customerid = y.customerid AND tripid='A2G0G5' AND registrationstatus!=3 
Error at Command Line:1 Column:9 
Error report: SQL Error: ORA-00933: SQL command not properly ended
00933. 00000 -  "SQL command not properly ended"

2 个答案:

答案 0 :(得分:2)

我认为你的问题就在这一行:

DELETE CUSTSEGCONTROL.x

您似乎试图从x删除列CUSTSEGCONTROL,这是无效的。

试试这个:

delete custsegcontrol x
where  x.customerid in
       ( select y.customerid 
         from   custsegcontrol y
         where  x.custsegcontrolid < y.custsegcontrolid 
         and    tripid = 'A2G0G5' 
         and    registrationstatus != 3
       )

答案 1 :(得分:0)

以下版本应在Oracle中有效。具有讽刺意味的是,这在MySQL中不起作用:

DELETE FROM CUSTSEGCONTROL x
    WHERE EXISTS (SELECT 1
                  FROM CUSTSEGCONTROL y 
                  WHERE x.custsegcontrolid < y.custsegcontrolid AND
                        x.customerid = y.customerid AND
                        tripid = 'A2G0G5' AND
                        registrationstatus <> 3
                 );