Error on Update Join

2019-03-05 06:00发布

问题:

I'm receiving this error

This is my Current error: ORA-00971: missing SET keyword

UPDATE FGMULTI (JOIN arinvt ar 
 ON  fgmulti.arinvt_id = ar.id)

 SET NON_CONFORM_ALLOCATABLE = 'Y'

 WHERE IN_Date = CurrentDate 
  AND ar.Class LIKE 'CP%' 
  (OR ar.Class LIKE 'FG%' 
  OR ar.Class LIKE 'IN%' 
  OR ar.Class LIKE 'LA%' 
  OR ar.Class LIKE 'PK%')

回答1:

use update for select by join

 UPDATE (select NON_CONFORM_ALLOCTABLE
         from FGMULTI 
          JOIN arinvt ar 
          ON  fgmulti.arinvt_id = ar.id 
         WHERE IN_Date = CurrentDate 
         AND ar.Class LIKE 'CP%' 
         OR ar.Class LIKE 'FG%' 
         OR ar.Class LIKE 'IN%' 
         OR ar.Class LIKE 'LA%' 
         OR ar.Class LIKE 'PK%') t
 SET t.NON_CONFORM_ALLOCATABLE = 'Y' 


回答2:

You can't use a JOIN in Oracle in an UPDATE statement. You can do that using and exists clause:

UPDATE FGMULTI
   SET NON_CONFORM_ALLOCATABLE = 'Y'
 WHERE IN_Date = CurrentDate 
  AND exists (SELECT 1 
              FROM arinvt ar 
              WHERE fgmulti.arinvt_id = ar.id
               AND (ar.Class LIKE 'CP%' 
                 OR ar.Class LIKE 'FG%' 
                 OR ar.Class LIKE 'IN%' 
                 OR ar.Class LIKE 'LA%' 
                 OR ar.Class LIKE 'PK%'));