PL/SQL Looping a table and copying some values to another one...

hi all!!!
i'm totally new to pl/sql, and i need to create an interaction to do the following..
my scenario is:
i have a table called "references" that contains 2 columns (new_id, old_id).
then i have another table called "ref" which also contains 2 columns (old_id, other_id).
ok the point is this:
in the table references i have stored the references between 2 products (the old one and the new one) by storing their ids.
now what i have to do by knowing this, is to insert in the table "ref" a new entry for every old_id that is already stored there, but changing it with the new_id that i can get from the other table (references).
let's see an example:
table references:
new_id - old_id
11 - 3
12 - 7
13 - 5
table ref:
old_id - other_id
3 - tu7r
7 - asduih
7 - anotherone
7 - 44444
5 - 6754f
so the result that i want is that the new ids (11,12,13) has to be copied to the table "ref" with the same "other_id" as their correspondants in "references" table.. the result would be:
table ref:
old_id - other_id
3 - tu7r
7 - asduih
7 - anotherone
7 - 44444
5 - 6754f
11 - tu7r
12 - asduih
12 - anotherone
12 - 44444
13 - 6754f
i don't know how to build up a loop or something to reach this aim!!
thanks for your time guys!!!
Edited by: ElMazzaX on Nov 17, 2011 3:15 PM

You do not need pl/sql to do this.
If I understand your datamodel correctly, this join will get you those records you need to insert:
select
references.new_id, ref.other_id
from references
join ref
   on ref.old_id = references.old_id;Try that select - it it works, then you can simply do:
insert into ref (old_id, other_id)
select
references.new_id, ref.other_id
from references
join ref
   on ref.old_id = references.old_id;SQL is quite enough - no PL/SQL loop necessary ;-)

Similar Messages

  • Dynamic Column Names from one table and its corresponding values from another table

    I have 2 tables. First tables gives the specification if a column is required or not. we have the 2nd table with the same column name where we provide the actual values.
    I want to select all the required columns from the 1st table and retrieve the values for those from the 2nd table. Both this i want to achieve in a single select statement.

    This wil require a dynamic Query with a Pivot
    DECLARE @ColsPivot as VARCHAR(MAX);
    DECLARE @Query  AS VARCHAR(MAX);
    1. Retreive the ID for all required field
    SET @ColsPivot = (SELECT STUFF((SELECT  ',' + quotename(CAST([RequirementID] as varchar(3))) FROM [dbo].[Requirement] WHERE required=1 FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)') ,1,1,''));
    This will give you : [1],[2],[3],[8],[9],[14] for exemple.
    2. Build your Query
    SET @Query ='SELECT ClientID,'+@ColsPivot+''
        FROM (
            SELECT [ClientID],[RequirementID],[Value]
            FROM dbo.RequirementValue
            WHERE ClientID=@CliendID --Optional SP parameter
        )src
              PIVOT(
                MAX(Value)
                for [RequirementID] in ('+@ColsPivot+')
        ) p';
    3. Exec(@Query);

  • SQL LOADER , EXTERNAL  TABLE and ODBS DATA SOURCE

    hello
    Can any body help loading data from dbase file .dbt to an oracle 10g table.
    I tried last day with SQL LOADER, EXTERNAL table , and ODBC data source.
    Why all of these utilities still failing to solve my problem ?
    Is there an efficient way to reach this goal ?
    Thanks in advance

    export the dbase data file to text file,
    then you have choice of using either sql loader or external table option to use.
    regards

  • How can i Delete all foto from my iphone and after some time get them one more time on it but not as a new album :)?

    How can i Delete all foto from my iphone and after some time get them one more time on it but not as a new album, i want them in the camera roll ?

    How can I delete EVERY THING off my Mac and have it like new?
    Boot from the software install DVD and do an "erase and install" when prompted.

  • Apple took money out of my account. I had to change debit cards, and they won't get another one so is there anything I can do about this problem. I rather cancel the phone before I have to worry with my bank accoung.

    Apple took money out of my account. I canceled my charge card and will not give them another one. Is there anything else I can do? I will cancel my account before I worry with my bank acount all the time. Now I can't even sign in for free apps

    OK, so I have now found that this is apparently normal for iTunes, to only accept mpeg 4 movie files, all the searching I did before I must have worded it wrong because I couldn't find anything about this, incredibly. Had been looking for why iTunes won't take all the files it previously did, like if it had been changed, and it hasn't, it's allegedly always taken only mpeg 4 files. Also I had been searching for why iTunes crashes every time I try and add/import anything but mpeg 4 files, and even sometimes with mpeg 4 files. That isn't normal, it's supposed to just do nothing apparently as I've just found out. So for these reasons I didn't find the answer despite my searching all over the web.
    So I guess that answers my own question now, but I'm still perplexed as to why I absolutely, definitely, without any doubt, had several hundred movies of a few different video file types loaded, accessible and playable in my iTunes library that everything here claims iTunes never accepted. It apparently shouldn't have been possible for me to have done this, but for probably 10 years it's been this way.
    Perhaps since I don't remember adding these files to iTunes anymore recently than maybe 6 or 7 years ago, the iTunes back then did accept all kinds of file types? Or could I have somehow had some video codecs or software that expanded the capability of my movie players like Quicktime Player that unwittingly also allowed iTunes to take those files as well? All I know is somehow it worked! So now my question is how did I have it working before, so that maybe I can make it work again.

  • My computer died and I had to buy another one.  Now I can't sync my ipod classic.  What is the deal with this?  I added songs about three months ago and it was fine.  Now it won't sync.  It says it has a duplicate file.

    My computer died and I had to buy another one.  Now I can't sync my ipod classic.  What is the deal with this?  I added songs about three months ago and it was fine.  Now it won't sync.  It says it can't sync because there is a duplicate file.

    There are server problems right now with iMessage effecting some users.  See http://www.apple.com/support/icloud/systemstatus/.

  • HT201269 My old windows computer crashed and I had to buy another one.  I rescued my itunes file off of the old one and installed it on the new desktop.  How do I get itunes to recognize it so that I can get all my old music (mostly burned CD's) to be rec

    My old windows computer crashed and I had to buy another one.  I rescued my itunes file off of the old one and installed it on the new desktop.  How do I get itunes to recognize it so that I can get all my old music (mostly burned CD's) to be recognized

    Syncing to a "New" Computer or replacing a "crashed" Hard Drive: Apple Support Communities

  • HT204053 I have a big problem in my account in Game Center .. I have been an account before in the game center and i change it to another one ...when i play any game its change by itself to the last account not still to the new one and i lost my update in

    I have a big problem in my account in Game Center ..
    I have been an account before in the game center and i change it to another one ...
    when i play any game its change by itself to the last account not still to the new one and i lost my update in my game
    How can i keep the new account in my game center and didn't change again ?
    My new account is :[email protected] ............Thats i wanna to keep it
    The old one is :michael-adel [email protected]
    Thank you

    I have a big problem in my account in Game Center ..
    I have been an account before in the game center and i change it to another one ...
    when i play any game its change by itself to the last account not still to the new one and i lost my update in my game
    How can i keep the new account in my game center and didn't change again ?
    My new account is :[email protected]. ............Thats i wanna to keep it
    The old one is :michael-adel [email protected]
    Thank you

  • I would like to cancel all itune charges on my credit card there is one for 4.99 and .99 now I see another one for 7.95 as of March 16 Please cancel all of them. I didn't charge them.

    I would like to cancel all itune charges on my credit card there is one for 4.99 and .99 now I see another one for 7.95 as of March 16 Please cancel all of them. I didn't charge them.

    Do what Roger says above.
    Do you have 'in-app' purchases enabled on an iPhone/iPad or other device that kids or other family members use ?  That could be the issue.
    If not change your iTunes Store password to try to prevent whatever is doing this making further charges.
    Also if you can't find the cause, talk to your cc company.

  • After updating to iOS7 I am trying to log in the Game Center with my  user ID  and it says that is in use and I need to enter another one?

    After updating to iOS7 I am trying to log in the Game Center with my  user ID  and it says that is in use and I need to enter another one?

    You may be able to find your Apple ID at Look up your old and forgotten Apple ID

  • Adding fields to database table and copying data from other fields

    Hi All,
    I am having a database table where in I am having a column 'FIELD1'.
    My requirement is that I want to add two more fields in the table 'FIELD2' and 'FIELD3'.
    I then want to copy all the data in field1 to field2 and field3. then I want to delete the original field1.
    for Ex.
    lets say FIELD1 = 100.
    now I want to add FIELD2 and FIELD3 in the table and make FIELD2 = 100 AND FIELD3 = 100. The FIELD1 will be deleted from table.
    Please suggest the methods to do so.
    It is urgent.

    Hi Gaurav,
    do this way ...
    data : begin of it_ztab occurs 0 with header line,
              fld1 like ztab-fld1,
              fld2 like ztab-fld2,
              fld3 like ztab-fld3,
            end of it_ztab.
    data : wa_ztab like it_ztab.
    it_ztab-fld1 = '100'.
    append it_ztab.
    clear    it_ztab.
    loop at it_ztab.
      wa_ztab-fld2 = it_ztab-fld1.
      wa_ztab-fld3 = it_ztab-fld1.
      wa_ztab-fld1 = ' '.
    * Make sure that the structure of internal table/ workarea and database table shoud be same
      modify ztab from wa_ztab.
    endloop.

  • Add Row in table and copy the properties from previous row

    Hello,
    i have a table with just one row (and 7 columns). The cells (columns) are
    all of different types, f.e. ring, numeric, string.....On runtime the user
    can add more rows to the table. I'm looking for a function to copy a row
    with all the cell propertis (cell type, format, text style....) and insert
    as a new row. Is there an easy way to do this?
    Thanks
    Norbert

    Thank you Luis,
    thats exactly how i thought it shoul work. I created a table with 7 columns
    and 1 Row and in the UI Editor i configured each column. The first column is
    set to ring, second colum is a set to numeric (default val 0.0000), double,
    with the precision 4 and the text justification set to CENTER CENTER. On
    runtime the user pushes a button that calls the function
    InsertTableRows(panel, PRUEFKREIS_TABLE, -1, 1, VAL_USE_MASTER_CELL_TYPE);
    That there are no default values in the new line is ok following your
    explanation, but when i enter a value in the second column of the new row i
    expect to get it formated with precision 4 and jaustification CENTER CENTER,
    but that doesnt work. If i enter a 2 i expect to get 2.0000 in the center of
    the cell, but i just get 2 in the upper left corner.
    i'm using LabWindows/CVI 2009 Version 9.1.0 (427).
    Any idea what i'm doin wrong ? The table mode is set to column. I also
    removed the ring columns to test if they cause the probplem, but still got
    the same error.
    Norbert
    "LuisG" <[email protected]> schrieb im Newsbeitrag
    news:[email protected]...
    > Norbert, Roberto's method allows you to create your new cells with the
    > cell attributes that you have defined for each column. Once you define
    > these attributes by configuring each column in the UI Editor (Edit
    > Table&gt;&gt;Edit Column&gt;&gt;Edit Default Cell Values), you can ensure
    > that each new cell created under that column inherits those attributes. By
    > attributes, I'm referring to items such as the cell type, or the text
    > style. Sadly, however, you can't inherit the cell values themselves. One
    > thing you could do is to go ahead and create the new cells and then use
    > the functions ClipboardGetTableVals and ClipboardPutTableVals to copy the
    > values from the first row to the new row. However, you will still have a
    > problem with your ring cells, since the entire list of items that each
    > ring cell holds is not considered an attribute (therefore, you can't
    > define it ahead of time in the column) but it also is not copied to the
    > clipboard. Only the current value is copied, I believe. So you'll have to
    > recreate this list for new ring cells each time. I'm sorry that this isn't
    > as easy as it should be... Luis

  • Question on Creating table from another table and copying the partition str

    Dear All,
    I want to know whether is there any way where we can create a table using another table and have the partitions of the new table to be exactly like the used table.
    Like
    CREATE TABLE TEST AS SELECT * FROM TEMP;
    The table TEMP is having range and hash partitions.
    Is there any way when we use the above command, we get the table partitions of TEMP to be copied to the new table TEST.
    Appreciate your suggestions on this one.
    Thanks,
    Madhu K.

    may this answer your question...
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:595568200346856483
    Ravi Kumar

  • Call type table and service threshold value

    I see for the call types where the service threshold value is set to default, the service threshold is shown as NULL in the Call type table. 
    Howver when you decide to override it, it shows the actual value.  Any reason why Cisco decided to have a NULL value for default and not the numeric one . (it is actually 20s)

    Please go through documentaton of all features that you required
    For India Payroll
    40ECS
    40CLM
    40LTR
    40EPF
    40PTX
    PPMOD
    DTAKT
    40ECC
    40ACK
    LGMST
    TARIFF
    For Time Management
    SCHKZ
    TMSTA
    QUOMO
    WWEEK
    WRKHR
    VTART
    MASEX
    HRSIF
    LDAYW
    TIMTA
    are some features, go to each and individual feature through PE03 and check the documentation , you can able to get an idea about the return values
    >If you want to see the complete list of feature
    >Go to PE03 give ***** at the field of feature name and press F4
    OR
    >Please run the program program RPUMKD00 ( through SE38)
    >Give value ***** in the FROM  field and keep the TO filed blank   for the selection of FeaturesLeave the Person Responsible fields blank
    >Give 1 for as in put  to the field Type of feature
    >Give 1 for as in put  to the field Version
    >Give 1 for as in put  to the field Activation indicator
    >and execute (F8)
    Select the required one from the list and go for documentation
    Edited by: Sujith Nambiar on Sep 17, 2010 2:48 PM

  • Generate xml from a table and insert the xml into another table

    I want to generate an xml file from a table and insert it into another table all in one tsql
    insert into table B(xmlfile)
    select * from tableA
    FOR
    XML
    PATH('ac'),TYPE,ELEMENTS
    XSINIL,ROOT('Accum')
    Is not working any help

    I have solved my issue all I did was to change my column datatype to xml

Maybe you are looking for

  • IPhone 5S cannot make purchase with App Store (login issue)

    Ok - I am rather irritated.  I tried to purchase a 99 cent app, and upon tapping the purchase button, the App Store insisted that I enter my Apple ID password (what happened to using your fingerprint, which worked when I bought the phone?).  Ok - so

  • Not Able to Use Gtalk in Curve 9320 Via my Sim data but internet is working as i checked via browser

    Hello,            Not Able to Use Gtalk in Curve 9320 Via my Sim data but internet is working as i checked via browser & i also use youtube but not able to login any messaging option & not able to creat Email account Please Help! Thanku Shivam

  • New firmware????nokia e90

    where can i get the new firmware that people are talking about?any ideas?

  • Accumulated total grouped by BP

    Hi All, I have written a query for customer aging report. I have saved it and generated it into QPL. I have grouped the report under Sales Employee and by Customers. The next thing i wanted to do is accumulating the total group by customers. I am usi

  • Can You Send A Clip To Motion?

    I don't have the tools I need in FCPX to complete a title sequence as I would like, so I thought I'd just send the clip to Motion and work with it there.  Is this possible in FCPX?  I don't see it in the help document. Thanks, Lawrence