Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to mass update one table, from another

LostInPermuationSep 6 2013 — edited Sep 6 2013

Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

PL/SQL Release 11.2.0.3.0 - Production

CORE    11.2.0.3.0    Production

TNS for Solaris: Version 11.2.0.3.0 - Production

NLSRTL Version 11.2.0.3.0 - Production

I have two tables, table A is basically a revised dataset of table B, linked with a pk/fk relationship.  What would the best method of updating two columns in table B, with the data from table A?

This is what I'm working on  now, but it isn't working.  Just wondering before I spend too much time trying to make it work if I'm on the right track or not.

SET SERVEROUTPUT ON

DECLARE

   v_data   VARCHAR2;

BEGIN

   FOR rec_info

      IN (SELECT admin_cn_fk, svexpand, nvexpand

            FROM nris_wbetters.fy07_reconciled_weights_final)

   LOOP

    select '''update fs_nris_nvum.nrn_weights set svexpand ='||

        rec_inf.svexpand||

        'nvexpand = '||

        rec_inf.nvexpand||

        'where admin_cn = '||

        'rec_inf.admin_cn_fk'''

        from dual into v_data;

    DBMS_OUTPUT.PUT_LINE(v_data);

    END LOOP;

    END;

/

My goal here is to basically generate all the update scripts as an output...that I can then run as a batch script.

Maybe later on I would  trust it to just run, but for now I want to see what is updating before it does it.

Here is an example of the data....

select

c.*

from

NRIS_WBETTERS.FY07_NRN_ADMIN  A

,NRIS_WBETTERS.FY07_RECONCILED_WEIGHTS C

where A.ADMIN_CN = C.ADMIN_CN_FK

and C.ADMIN_CN_FK in ('6D7DDD44FFA9A890E043A602B810A890','6D7DDD44FFAAA890E043A602B810A890','6D7DDD44FFABA890E043A602B810A890')

;

IDSVEXPANDWEIGHTS_CNNVEXPANDADMIN_CN_FKVPDUNIT_ID
491

349.4

6E0DF27410139F36E043A602B8109F36

349.4

6D7DDD44FFA9A890E043A602B810A8900103
492

349.4

6E0DF27410149F36E043A602B8109F36

349.4

6D7DDD44FFAAA890E043A602B810A8900103
493

349.4

6E0DF27410159F36E043A602B8109F36

349.4

6D7DDD44FFABA890E043A602B810A8900103

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 4 2013
Added on Sep 6 2013
17 comments
885 views