Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using update from the same table with ORACLE

I’m trying to update a field from my table using another field from the same table, but when I run the update below I get an error

update f1
set f1.usu_cgcstr = f2.cgccpf
from E095for as f1
join E095for as f2
on f1.codfor = f2.codfor
where  f1.usu_intot = 'N'

Error:

  1. 00000 – "SQL command not properly ended"

So how I can do this update?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Wrong syntax; use merge:

merge into f1
  using e095for f2
  on (f1.codfor = f2.codfor)
  when matched then update set f1.usu_cgcstr = f2.cgccpf
  where f1.usu_intot = 'N';

Or, if you wanted update:

update e095for f1 set
  f1.usu_intot = (select f2.cgccpf
                  from e095for f2
                  where f2.codfor = f1.codfor
                 )
  where f1.usu_intot = 'N'
    and exists (select null from e095for c
                where c.codfor = f1.codfor
               );
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading