SQL 开发者使用 join 命令删除一行

SQL Developer delete a row using join command

我正在使用以下命令通过 JOIN 查询删除 REL_CLIENT_CAT table。但是在控制台中遇到以下错误。当我 运行 在 sql 开发人员中时,给定的查询无法正常工作。

delete RL_CLIENT_CAT rlcc 
 join CLIENT_CATEGORY cc on cc.client_id = rlcc.client_category_id
 where rlcc.clientId='298860' and cc.code='client1'

我得到的错误信息

delete RL_CLIENT_CAT rlcc 
 left outer join CLIENT_CATEGORY cc on cc.client_id = rlcc.client_category_id
  where rlcc.clientId='298860' and cc.code='client1'
Error at Command Line : 10 Column : 2
Error report -
SQL Error: ORA-00933: SQL command not properly ended
00933. 00000 -  "SQL command not properly ended"
*Cause:    
*Action:

请告诉我。

DELETE 使用 join 在 oracle 中是不可能的。相反,您可以使用以下查询:

DELETE RL_CLIENT_CAT RLCC
 WHERE RLCC.CLIENT_CATEGORY_ID IN (
    SELECT CC.CLIENT_ID
      FROM CLIENT_CATEGORY CC
     WHERE CC.CODE = 'client1'
)
   AND RLCC.CLIENTID = '298860';

或者您可以使用 EXISTS 的相关子查询,如下所示:

DELETE RL_CLIENT_CAT RLCC
 WHERE EXISTS (
    SELECT 1
      FROM CLIENT_CATEGORY CC
     WHERE RLCC.CLIENT_CATEGORY_ID = CC.CLIENT_ID
       AND CC.CODE = 'client1'
)
   AND RLCC.CLIENTID = '298860';