Update the values in the Table from another Table containing historical data

So, I have two tables, a table and a master table.  The current table is updated each week and at the end of the week, is copied to the main table to keep historical data.  I have update the table in progress early in the week and want to take the latest data from the master table and update the current table with the data.  The current table could have additional IDs or some of the IDS could have deposited (these lines would receive data in the main table).  I want to only update the rows in the current table that have existing data to the attr1, attr2, attr3 columns.  A particular ID may have more than one record in the primary table, I want only the last disk to use for updating the current table.  The data from a different database where no direct connection is possible then I have to import data every week.  Here are some statements of create/insert:

create table current_T (ID1 varchar(100),adate date,attr1 varchar(100),attr2 varchar(100),attr3 varchar(100))

create table Master_T (ID1 varchar(100),adate date,attr1 varchar(100),attr2 varchar(100),attr3 varchar(100))

begin
insert into current_T (ID1,adate)
values ('IE111','08/02/13');
insert into current_T (ID1,adate)
values ('IE112','08/02/13');
insert into current_T (ID1,adate)
values ('IE113','08/02/13');

insert into master_T (ID1,adate,attr1,attr2,attr3)
values ('IE111','08/01/13','yes','abc','123');
insert into master_T (ID1,adate,attr1,attr2,attr3)
values ('IE112','08/01/13','no','dgf','951');
insert into master_T (ID1,adate,attr1,attr2,attr3)
values ('IE113','08/01/13','no','dgf','951');
insert into master_T (ID1,adate,attr1,attr2,attr3)
values ('IE113','07/01/13','no','dgf','951');
end;

This has been a scratcher for me head and any help would be greatly appreciated.  I'm coding in Apex 4.1

Thank you

-Steve

Not tested

merge into current_t c

using (select *)

Of

(select m.*

row_number() over (partition by m.id1 m.adate DESC order) rn

of master_t m

)

where rn = 1

) u

on (c.id1 = u.id1)

When matched then update

Set c.adate = u.adate

c.attr1 = u.attr1,

c.attr2 = u.attr2,

c.attr3 = u.attr3,

When not matched then insert

(c.id1, c.adate, c.attr1, c.attr2, c.attr3)

values

(u.id1, u.adate, u.attr1, u.attr2, u.attr3)

;

Tags: Database

Similar Questions

  • How to update the table when change list item in the classic report

    Hello
    I worked with apex 4.2 and I create normal classic report with list (named loved) select a column, now I want to update the table when the user changes the list with the new value, I can't create a dynamic action to do this, I create checkbox with the primary key and the loop for check point to update the table but I can not get the value of the list item. and for more speed, the user want to do it when changing the value from the list.

    My question
    1. how to do it in javascript and get the value of the list item and update the table with the new value
    2. do I have to use the API to create the list item so I can get the value of the report item or what.





    Thank you

    Ahmed

    You can find a lot of information in this forum (and outside in google) when you search for AJAX processes and demand. However, the tutorial in the link below should be useful:
    http://www.Oracle.com/WebFolder/technetwork/tutorials/OBE/DB/hol08/apexweb20/ajax_otn.htm

    BTW, if we answer your question, don't forget to mark the appropriate post as correct. It will help all of us in the forum.

  • How do I update the table in Jdev

    Hello

    I use Jdev 11.1.1.7.1.

    The control of data, I added that ADF only read the table. When I click on the button create and return to the report screen, highlight lines are added.

    Highlighted those who is not inserted into the DB table but he showed in the report. How to remove it. How can I update the table?

    Kindly advice me.

    Thank you

    Swathi

    That's what I got:

    -You have a table read-only, and a link to create.

    -When you press the link create a popup will be launched with a new record (may be a form in the same table iterator).

    -When you press save to save the changes validation triggers, stop you to insert the record.

    -After the fire of validation you will close the pop-up window (by pressing icon or by pressing Cancel).

    -After closure of the pop-up window, you will find that reading one table has some blank lines.

    If it is your problem if you have 2 choices:

    1. in the AppModule you can make a new instance on the view object (to which redirect the table) If your view object called 'EmployeesView', so, in AppModule, you should have EmployeeView1 and EmployeeView2 and your table may point to EmployeeView1, and when you create new line create in EmployeeView2 and after completing the creation you can run the query and then refresh the table (as shown in the following code).

    2 - the second option in the popup cancelListener link at the rear bean method then you can update the table by program as:

        DCIteratorBinding iter = (DCIteratorBinding) BindingContext.getCurrent().getCurrentBindingsEntry().get("TableIteratorName"); // from pageDef.
        iter.getViewObject().executeQuery();
        RequestContext.getCurrentInstance().addPartialTarget(getTableComponent());// from table Binding property bind it to object in back bean
    
  • Update the Table of Adf

    Hi all

    I have a page jspx, with a table and a button.

    Create the table data control, and it contains 4 columns

    (Name, card student, asked (Question or answer)).

    I create the code for the button to work

    1. Select a record

    2 send email

    3. when I send the request goes from Q to A

    All work fine. The mail has been sent. The demand for DB password Q has. But in my jspx table refreshes.

    Until I close and open again, it displays all the data.

    How cal I solve it?

    Thanks in advance

    Christos.

    Simply add partialTrigger on table pointing to the button.

    It will update the table when the button is clicked.

  • I have different bookmarks I want to keep on each computer, synchronization will delete the bookmarks on a single computer and replace the bookmarks from another computer in their place

    I have not yet used sync, but I sense it's going to be a problem if I do. I have different bookmarks I want to keep it on each computer. Sync will delete the bookmarks on a single computer and replace the bookmarks from another computer in their place? So I think that will erase the bookmarks on the second computer you configured to synchronize. Is there a way to merge bookmarks on every computer in the library of a bookmark that contains all bookmarks on both computers, so I'm not all bookmarks in sync?

    Just to be clear, this is something that we have commented several times in the forum, Firefox Sync adds everything that is already in the device for the account and pushes this info for the rest of the devices.

    So if you have 2 computers with data X and the other with the data from there, once you set up synchronization in both computers you will have X + Y at the same time.

    I hope that clarifies the doubts...

  • Satellite A100-549: BSOD after I used the recovery from another PC

    Hello.

    Had a few probs with my laptop and decided to recover it using another pc recovery disc.
    I get the laptop is a Toshiba a100-549. Unfortunately for some reason I can't disks that were originally with her.

    The opertaing system is Windows xp. The disks I got with a Vista.
    It loads OK but goes to a blue screen after 30 seconds and restarts. Is there a reason for this and can I do.

    I think I may need to get your hands on a good drive and load it on again.
    Someone at - it copies of drives for this laptop and able to send me their. I'll gladly pay for them...

    Colin

    Hello

    Don t user recovery drive to another PC, because it won't work.
    You can use a clean Windows OS disk or the Toshiba recovery disc.

    Why? Because the recovery disk contains an image. The image is a package containing a Windows OS, drivers and other software.
    If you want to use the recovery from another PC disk then all the drivers, tools and software distributed for this PC will be loaded on your Toshiba laptop.
    This can cause the BSOD!

    So if you n t have the Toshiba recovery disc then you should use MS Windows CD!
    Toshiba drivers can be downloaded from the Toshiba page!

  • Time capsule will not recognize the backup from another mac

    Time machine will not recognize the backup from another mac

    Time Machine will never find "another" Mac backups unless you've been backup that 'different' Mac on the same Capsule you have there.

    So, we need more information and to try to understand what it is that you are trying to accomplish. Please assume that we know nothing about what you could have done in the past... (since we don't have).

  • Update the Bios from f29 to f2b?

    Can someone tell me if the update of Bios f.2bs will actually be an improvement over my current bios F.29?

    With the exception of the occasional router connection overnight downturn, (usually after 12 or so when everything seems to hang, but this does not happen if I use a cable network however), everything is fine.

    This update was suggested my HP support assistant. I checked the page to update the driver from the Hp website for my model (dv6-7000 quad, win7 64 bit) and it appears an old bios f.0Une update.

    Please provide improvements that never I don't see if I choose to upgrade.

    Thank you

    Hello

    Please go through this thread and read the advice given by HP Expert (Dragon-fur) on updating the BIOS: http://h30434.www3.hp.com/t5/Notebook-Operating-Systems-and-Software/bios-update/m-p/4102072

    I think take made House are:

    DO NOT UPDATE BIOS/FIRMWARE OF YOUR SYSTEM UNLESS IT IS NECESSARY TO CORRECT A DEFECTIVE/DISABLE-FUNCTIONING SYSTEM COMPONENTS

    DO NOT UPDATE BIOS/FIRMWARE JUST BECAUSE THE LATEST VERSION IS COMER & THIS WILL BE COOL TO HAVE

    ONLY UPDATE BIOS/FIRMWARE FROM THE SITE OF YOUR PRODUCT (NOT HPSA), TOO IF YOUR SYSTEM IS IN GREAT NEED OF HIM.

    I have no idea why updates, you referred has been deleted. HPSA is too bug eventhough it of a great tool for your computer, so be careful, you do everything related to him or her.

    Update my other updates to my product site as soon as it is available. I don't want to make a mess of everything in the end.

    Hope your problem is solved. I'm happy that I could help you.

    Thank you

  • Partition question - what would be the best way to increase its space and take part of the space from another partition

    Hello, I have my 500 GB SATA broken down into 3 partitions. Vista and 2 others. The problem is the process of using Partition Magic, Vista has been given only 30 GB, now its operation with 1-2 GB of free space. I want to know what would be the best way to increase its space and take part of the space from another partition, but I don't want to have to reinstall or do I want to lose all the data like photos, browser, documents and news ect.

    -Thank you

     

    You can read more details on "How to move from one partition to the other sapce without loss of data.

  • What API can be used to update the table cs_estimate_details (repair)

    I need to update the columns 'pricing_context' and 'pricing_attribute1' in the cs_estimate_details table.

    Which API can be used to update the columns. Where can I update the table directly?

    Try to use this "CS_Charge_Details_PVT" which in turn call "CS_ESTIMATE_DETAILS_PKG".

  • When we try to install all applications on the Cloud Office it crashes at 90%. If we run the application it works. If we try to update the application from the desktop cloud it hangs at 50%. We have already reconfigured MAC and re-installed the

    When we try to install all applications on the Cloud Office it crashes at 90%. If we run the application it works. If we try to update the application from the desktop cloud it hangs at 50%. We have already reconfigured MAC and re-installed the application of desktop application and cloud several times. The OS is Yosemite.

    Hello

    Please, try the following steps:

    • Log out of the desktop Adobe CC application. (https://helpx.adobe.com/creative-cloud/help/sign-in-out-activate-apps.html)
    • Set the "Read and write" permissions on the files of Adobe for all users in the following locations:
      • / Library/Application Support /.
      • /Users/ [user name] / Library/Application Support /.
    • Restart the computer.
    • Connect to the desktop Adobe CC application.

    Kind regards

    Sheena

  • How to update the table with the number management

    Hello

    I need as there is a loc_tab of the created table as below,

    CREATE TABLE loc_tab
    (
    Country_ID NUMBER,
    country_code VARCHAR2 (3),
    country_name VARCHAR2 (50).
    State_ID NUMBER,
    state_code VARCHAR2 (3),
    state_name VARCHAR2 (50).
    city_id NUMBER,
    city_code VARCHAR2 (3),
    city_name VARCHAR2 (50)
    );

    I inserted records like below,
    COUNTRY_ID     COUNTRY_CODE     COUNTRY_NAME     STATE_ID     STATE_CODE     STATE_NAME     CITY_ID     CITY_CODE     CITY_NAME
    
              IND          INDIA                    TN          TAMIL NADU          CHN          CHENNAI
              IND          INDIA                    TN          TAMIL NADU          TRI          TRICHY
              IND          INDIA                    TN          TAMIL NADU          CMT          COIMBATORE
              IND          INDIA                    TN          TAMIL NADU          MDU          MADURAI
              IND          INDIA                    AP          ANDHRA PRADESH          HYD          HYDERABAD
              IND          INDIA                    AP          ANDHRA PRADESH          SEC          SECUNDRABAD
              AUS          AUSTRALIA               QLD          QUEENSLAND          BRI          BRISBANE
              AUS          AUSTRALIA               TAS          TASMANIA          HB          HOBART
              AUS          AUSTRALIA               TAS          TASMANIA          CCE          CITY OF CLEARANCE
              AUS          AUSTRALIA               TAS          TASMANIA          BUR          BURNIE
    Now, I wanted to update the table such that all ID columns are updated with running number.

    Each ID columns should get incremented so that, for Country_ID column corresponding to "India" If country_id is 1, that there must be one for all the lines with the name as "India". Likewise for "Australia".

    In the case of State, she also has the same logic with numbers repeated until the very name of the State comes.

    For the city, it of course will hold separate ID only because the name of the city will not get duplicated.

    This update must be done in the normal way using simple SQL such as no PLSQL don't like looping, etc... is involved.

    Here are the contents of the table, and that's how the table should be updated,
    COUNTRY_ID     COUNTRY_CODE     COUNTRY_NAME     STATE_ID     STATE_CODE     STATE_NAME     CITY_ID     CITY_CODE     CITY_NAME
                                            
    1          IND          INDIA          1          TN          TAMIL NADU     1     CHN          CHENNAI
    1          IND          INDIA          1          TN          TAMIL NADU     2     TRI          TRICHY
    1          IND          INDIA          1          TN          TAMIL NADU     3     CMT          COIMBATORE
    1          IND          INDIA          1          TN          TAMIL NADU     4     MDU          MADURAI
    1          IND          INDIA          2          AP          ANDHRA PRADESH     1     HYD          HYDERABAD
    1          IND          INDIA          2          AP          ANDHRA PRADESH     2     SEC          SECUNDRABAD
    2          AUS          AUSTRALIA     1          QLD          QUEENSLAND     1     BRI          BRISBANE
    2          AUS          AUSTRALIA     2          TAS          TASMANIA     1     HB          HOBART
    2          AUS          AUSTRALIA     2          TAS          TASMANIA     2     CCE          CITY OF CLEARANCE
    2          AUS          AUSTRALIA     2          TAS          TASMANIA     3     BUR          BURNIE
    Thank you and best regards,
    Shiva
  • Flash as2 cross subject to access the SWF from another server domain

    I have question cross-domain, how do I access the .swf from another swf file without using System.Security.allowDomain() in the swf file, which we are called.

    I use 2 domains and I have 2 files swf is a.com (a.swf) and another is of bcom (b.swf) I want to access the file the a.swf b.swf frames, if I use the system.Security.allowDomain() in b.swf file I can access executives. But without using this way I can access the file from another domain.

    Because I have a risk to change the file b.swf so I vant to go without changing the file b.swf is any other wey to access frames of the file the file a.swf b.swf. Please someone help me solve this problem.

    use a local executable (such as php) to load the b.swf and send it back to a.swf.  for example:

    loadSWF.php:

    <>

    $fh = fopen ("www.b.com/b.swf", "r");

    Header ("Content-type: application/x-shockwave-flash");

    fpassthru ($FH);

    ?>

    a.fla:

    var target_mc:MovieClip=this.createEmptyMovieClip("target_mc",this.getNextHighestDepth());

    target_mc.loadMovie ("loadSWF.php");

  • Update the table on the dialog flow back task...

    Hi all

    I have a table. In a context menu of the table, a user uses a menu command to launch a workflow task merely as inline popup dialog box, which allows them to alter certain data associated with the selected line. It all works very well.

    What I'm trying to understand, that's how I trigger a refresh of partial page on the table once the workflow returned and the dialog box closes. I tried to call a support as target bean method of the "listener after" for the call activity of workflow that call the stubborn workflow, which calls AdfFacesContext.getCurrentInstance () .addPartialTarget (table), but which did not cause a refresh of the table. I waited a bit that would be the case.

    So, what event can I link at the right time in order to update the table?

    Thank you

    Hello

    When you open a workflow bounded in a small popup, then you use the earpiece back on the component that runs the pop-up window to refresh the table. On http://www.oracle.com/technetwork/developer-tools/adf/learnmore/index-101235.html, see example #69

    Frank

  • Update the table of contents, errors in bookmarks

    When I update my table of contenst, it creates errors in my favorites. I have a hierarchy of level three with my titles of paragraph in my table of contents. When I update the table of contents, it takes the last item in my lowest level and a level higher than it is actually.

    Any ideas of what is happening and how can I fix?

    OK, thanks to your last message, I began to explore the Table of contents dialog box and understood what the problem was. It had to do with the levels that I had assigned to the table of content items, which I was incompatible. Now I have the right levels assigned to the table of content items and it updated bookmarks perfectly!

    Thanks for your help.

Maybe you are looking for