sql update - Updating Multiple Columns from another table - Need Oracle format -
i have script use in sql server need convert oracle format. can help?
update persons p set p.jobtitle=te.jobtitle, p.last_name=te.last_name, p.first_name=te.first_name, p.dblogin_id=te.dblogin_id, p.email_id=te.email_id, p.userlevel=te.userlevel, p.facility_id=te.facility_id, p.supervisor=te.supervisor, p.department=te.department, p.winloginid=te.winloginid temp_ecolab_persons te p.person=te.person;
--from article below came following statement. still doesn't work unfortunately:
update (select p.jobtitle, p.last_name, p.first_name, p.dblogin_id, p.email_id, p.userlevel, p.facility_id, p.supervisor, p.department, te.jobtitle, te.last_name, te.first_name, te.dblogin_id, te.email_id, te.userlevel, te.facility_id, te.supervisor, te.department persons p, temp_ecolab_persons te p.person=te.person) set p.jobtitle=te.jobtitle, p.last_name=te.last_name, p.first_name=te.first_name, p.dblogin_id=te.dblogin_id, p.email_id=te.email_id, p.userlevel=te.userlevel, p.facility_id=te.facility_id, p.supervisor=te.supervisor, p.department=te.department;
this how it. might not best performance, works.
merge persons_tmp pt using ( select p.person, p.job_title, p.first_name, p.last_name, p.facility_id persons p) tmp on (pt.person = tmp.person) when matched update set pt.facility_id = tmp.facility_id, pt.job_title = tmp.job_title, pt.first_name = tmp.first_name, pt.last_name = tmp.last_name;
the script above update information in persons_tmp table using data persons table. believe in case, want other way around. so, please make sure make necessary changes before running script.
you can add "when not matched then.... " clause above sql in case need insert new records, if not exist.
Comments
Post a Comment