SQL:更新中内部联接的错误

时间:2017-12-02 17:41:13

标签: sql oracle sql-update inner-join

我无法在我的请求中发现问题。这是我的请求和2表:

UPDATE RESERVATION inner join client on reservation.numcl = client.numcl
SET reservation.numcl2 = client.numcl2;

错误:

   => [42000][971] ORA-00971: missing SET keyword
  1. 表客户端 Client table

  2. 预订客户 reservation table

  3. 解决方案:

    UPDATE RESERVATION SET reservation.numcl2 = (select client.NUMCL2
                                                 from CLIENT
                                                 where client.NUMCL= RESERVATION.numcl);
    

1 个答案:

答案 0 :(得分:0)

Oracle不支持join中的update(至少是明确的)。您想要做的事情的等价物是:

UPDATE RESERVATION r
    SET numcl2 = (select client.NUMCL2
                  from CLIENT c
                  where c.NUMCL = r.numcl
                 )
    WHERE EXISTS (SELECT 1 FROM client c WHERE c.NUMCL = r.numcl);

如果你想处理没有匹配的情况,exists很重要。