0

I search an update-command, which update me only some records (more than one row) in a table. The update Information comes from an other table. Unfortunately it updates all 3500 records instead of only 603 records. Here is the update/select. What is wrong:

update Z_VERTRAGSDATEN_HIST HIST
  set 
    (HIST.VERHI_BISDAT) = 
    (select
  UPDA.VERHI_BISDAT
     from
        Z_VERTRAGSDATEN_HIST HIST
        , Z_VERTRAGSDATEN_UPDATE UPDA
    where
        HIST.VERHI_VER_ID = UPDA.VERHI_VER_ID
    and
        HIST.VERHI_BISDAT != UPDA.VERHI_BISDAT   
    )
;
commit; 
1
  • 2
    You need to add a where condition if you don't want to update all rows. Jun 18 '15 at 6:46
0

I friend told me the solution:

update Z_VERTRAGSDATEN_HIST HIST
  set
    ( HIST.VERHI_BISDAT
    , HIST.VERHI_ENDE
    , HIST.VERHI_ZEITSTEMPEL
    )  =
    ( select
      UPDA.VERHI_BISDAT
      , UPDA.VERHI_ENDE
      , sysdate
     from
       Z_VERTRAGSDATEN_UPDATE UPDA
     where
       HIST.VERHI_VER_ID = UPDA.VERHI_VER_ID
     )
where 
  HIST.VERHI_VER_ID in 
  ( select 
      verhi_ver_id 
    from  
      Z_VERTRAGSDATEN_UPDATE
  )
;
commit;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.