Better method for update query

Thanks in advance for any help you can offer on this...
I have two tables:
DETAIL_TABLE with columns: email_address, invalid_format_indicator, source, create_date
SUMM_TABLE with columns: run_date, source, email_address_cnt, invalid_email_address_cnt
Each week I run a job that truncates, then inserts new rows into the DETAIL_TABLE of email addresses that are likely invalid (invalid_format_indicator = 'Y'), and the source system ("source") that created them, as well as the date they were created in our system. Later in the process of that same job, I add new rows into SUMM_TABLE with counts.
So, for data:
DETAIL_TABLE:
email_address|invalid_format_indicator|source|create_date
joe.aol.com|Y|web|2011-03-01
mary@myurl|Y|web|2011-03-05
larry 2yahoo.com|Y|phone|2011-03-06
After the DETAIL_TABLE is refreshed, new rows (14 of them) are inserted into the SUMM_TABLE whereby it creates a new row for each source. What I then want to do is update the 'invalid_email_address_cnt' field by counting the number of rows in DETAIL_TABLE, grouping by source.
Right now, I'm running 14 update queries simultaneously--one for each source.
Data looks like this after the update is complete (bear in mind, it's being updated via 14 separate queries):
SUMM_TABLE
run_date|source|email_address_cnt|invalid_email_address_cnt
2011-03-06|web|25|5
2011-03-06|phone|3|1
2011-03-06|loader|20|4
2011-03-06|source14|5|2
It looks like this BEFORE the update:
run_date|source|email_address_cnt|invalid_email_address_cnt
2011-03-06|web||
2011-03-06|phone||
2011-03-06|loader||
2011-03-06|source14||
I'm currently running this update statement:
Update SUMM_TABLE S
set invalid_email_address_cnt =
(Select count(*)
from DETAIL_TABLE D
where D.source = 'web'
and D.invalid_format_indicator = 'Y')
where S.run_date = sysdate
and S.source = 'web';
I repeat this query 13 more times-- one for each source. Ick...
I'd like to consolidate it to one query. I prefer not using PL/SQL. The tool I'm using doesn't support PL/SQL (It's an open source ETL tool), so if I can do this via straight SQL (Oracle compliant) that would be ideal.
Any help would be greatly appreciated!

I believe you just want a correlated update
Update SUMM_TABLE S
   set invalid_email_address_cnt =
      (Select count(*)
        from DETAIL_TABLE D
       where D.source = s.source
         and D.invalid_format_indicator = 'Y')
where S.run_date = sysdate;I'm not sure, though, about the WHERE clause. Surely you mean TRUNC(sysdate) or you're using a local variable that you used to insert the row into the summary table. Otherwise, if you get unlucky and the clock ticks while your procedure is running, the update may not affect any rows.
Justin

Similar Messages

  • For Update Query

    Hi All,
    I having block level 8000 records, I Scroll down from First record to last record it is takeing more time.
    I Observed tkproof while scrolling two select statments are running..
    1) pre-query block level
    2) For update query
    For update query -> How is is forming? Any Property or some else?
    I am not able to find the second query..where it is forming..How to restrict the second query.
    Query Array size - 10
    Number of records buffered - 10
    Number of records Displayed - 10
    Query all records - No
    Locking mode - Immediate
    Key mode - Automatic
    Version - Oracle 10g
    Plz ........any

    The for update -query is generaetd by forms when its locking the record. If you didn't change anything in the record "by hand", check if there is some code in the POST-QUERY-trigger which forces the record to be locked. if its the POST-QUERY you can issue the following command to avoid the lock at the end of the POST-QUERY:
    SET_RECORD_PROPERTY(:SYSTEM.TRIGGER_BLOCK, :SYSTEM.TRIGGER_RECORD, STATUS, QUERY_STATUS);

  • For Update Query with Wait Clause from ORACLE Forms

    Hi
    We are using Oracle Forms 10g running with 10g database 10.2.0.1.0. We happend to see a query which is getting generated in AWR report like Select rowid, all_columns from TableName for Update of C1 Nowait. But no such query is really written in forms and we are aware that, Any query prefixed with rowid is definitely executing from Forms. But how the ForUpdate and Nowait clause is appended to the query.
    We have checked the following properties in the database Block
    *1) Locking Mode is set to Automatic*
    *2) Update Changed Columns only is set to YES*
    *3) Query all records is set to No (Though this particular property may not be relevant to the issue)*
    What is the property or setting which might trigger such a query from ORACLE Forms with ForUpdate and Nowait clause.
    Any ideas/suggestions on why such behaviour. Please have a healthy discussion on this. Thanks in advance.

    Why have you started another thread on the same thing?
    FOR UPDATE cursor is causing Blocking/ Dead Locking issues
    Just use one thread to avoid confusion.
    The fact that nobody has answered on the other thread for a couple of days could be to do with it being the weekend and most people are not at work.
    Either be patient or, if it's more "urgent" than that, raise a SR/Tar with Oracle metalink.

  • FOR UPDATE query issue

    SELECT table_name FROM all_tables WHERE dropped = 'NO' and owner = 'test'
    FOR UPDATE;
    ERROR at line 1:
    ORA-02030: can only select from fixed tables/views
    ORA-06512: at line 9
    ORA-06512: at line 16
    Can any body help me out what is wrong in that query.
    Thanx

    SELECT table_name FROM all_tables WHERE dropped = 'NO' and owner = 'test'
    FOR UPDATE;What do you want to achieve from this?? Do you want to update the all_tables ?? :-)

  • For Update Query from ORACLE Forms

    Hi
    We are using Oracle Forms 10g running with 10g database 10.2.0.1.0. We happend to see a query which is getting generated in AWR report like Select rowid, all_columns from TableName for Update of C1 Nowait. But no such query is really written in forms and we are aware that, Any query prefixed with rowid is definitely executing from Forms. But how the ForUpdate and Nowait clause is appended to the query.
    We have checked the following properties in the database Block
    *1) Locking Mode is set to Automatic*
    *2) Update Changed Columns only is set to YES*
    *3) Query all records is set to No (Though this particular property may not be relevant to the issue)*
    What is the property or setting which might trigger such a query from ORACLE Forms with ForUpdate and Nowait clause.
    Any ideas/suggestions on why such behaviour. Please have a healthy discussion on this. Thanks in advance.

    you can't dynamically add a query to the data model in reports.
    You should look into the XML based customization of Oracle Reports. This will enable you to define a report dynamically by creating a definition in XML.
    Also another option is to have the report with a query in it and use lexical parameters in reports to pass the query definition or just the where part of it.
    Look at the reports online help for both of these solutions.

  • What's the method for updating a book?

    I use a variation of FrameMaker 10's FM_Outputs_CondText.jsx to automate generation of PDFs.
    What do I need to add to force a book update?
    It looked to me as if it were doing that, but I just noticed that the build date variable in the front matter is updated only when I manually update the book.

    To be a little more elaborate: I checked the script you mentioned and it only updates cross-references when opening a book and its files. That is not the same as updating the book and all its variables. You do need to use the Book.UpdateBook method for that explicitly, after first opening all files in the book. That amounts to the same as manually updating the book.
    Ciao again

  • Select for update query not working..

    hi i am tying to get this bit of ncode to work so i can then go to the next part of demonstrating a deadlock between two transactions. however i cannot go any further has my initial code does not work at all. here it goes
    //////////User A////////////////////////////////
    DECLARE
    v_salary squad.salary%TYPE := 300;
    v_pos squad.position%TYPE := 'Forward';
    BEGIN
    UPDATE squad
    SET salary = salary + v_salary
    WHERE sname = 'Henry';
    FOR UPDATE;
    UPDATE squad
    SET position = v_pos
    WHERE sname = 'Fabregas';
    COMMIT;
    END;
    //////////////////////User B/////////////
    DECLARE
    v_salary squad.salary%TYPE := 200;
    v_pos squad.position%TYPE := 'Forward';
    BEGIN
    UPDATE squad
    SET position = v_pos
    WHERE sname = 'Fabregas';
    FOR UPDATE;
    UPDATE squad
    SET salary = salary + v_salary
    WHERE sname = 'Henry';
    FOR UPDATE;
    COMMIT;
    END;
    Basicly user a creats a lock and so does user b, user b enquires a lock from user a and vice versa i.e. a deadlock

    Hi
    You get the following error:
    ORA-06550: line 8, column 7:
    PLS-00103: Encountered the symbol "UPDATE" when expecting one of the following:
    because the FOR UPDATE; is invalid in your statement.
    Try this:
    //////////User A////////////////////////////////
    DECLARE
    v_salary squad.salary%TYPE := 300;
    v_pos squad.position%TYPE := 'Forward';
    v_n number;
    BEGIN
    UPDATE squad
    SET salary = salary + v_salary
    WHERE sname = 'Henry';
    select 1 into v_n from squad
    WHERE sname = 'Fabregas'
    for update;
    UPDATE squad
    SET position = v_pos
    WHERE sname = 'Fabregas';
    COMMIT;
    END;
    //////////////////////User B/////////////
    DECLARE
    v_salary squad.salary%TYPE := 200;
    v_pos squad.position%TYPE := 'Forward';
    v_n number;
    BEGIN
    UPDATE squad
    SET position = v_pos
    WHERE sname = 'Fabregas';
    select 1 into v_n from squad
    WHERE sname = 'Henry'
    for update;
    UPDATE squad
    SET salary = salary + v_salary
    WHERE sname = 'Henry';
    COMMIT;
    END;
    To syncronize the blocks first in a SQLPlus call these two statements:
    select 1 from squad WHERE sname = 'Fabregas' for update;
    select 1 from squad WHERE sname = 'Henry' for update;
    After this start the user A code in another SQLPlus, and start the user B code. After this call rollback or commit in the first sqlplus.
    Ott Karesz
    http://www.trendo-kft.hu

  • Select for update query

    with :
    resultset = stmt.executeQuery("select nxtid from mytable .. for update");
    I have the ora-1002 Erreur.
    Could you help me.
    null

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by burgniar:
    with :
    resultset = stmt.executeQuery("select nxtid from mytable .. for update");
    I have the ora-1002 Erreur.
    Could you help me.<HR></BLOCKQUOTE>
    Solution is :
    conn.setAutoCommit(false);
    null

  • Is there any better way for updating table other than this?

    Hi all, I need to update a row in the table that require me to search for it first (the table will have more than hundred thousands of row). Now, I am using a LOV that will return the primary key of the row and put that primary key to DEFAULT_WHERE property in the block and execute query command to fetch the row that need updating. This works fine except that it require 2-query-trip per update (the lov and the execute_query). Is there any better way to doing this? This update is the main objective for my application and I need to use the most effective way to do it since we need to update many records per hour.

    Thanks Rama, I will try your method. Others, how to query row instead of primary key? I thought that querying primary key is faster due to the index?
    BTW, what people do if you need to update a table using Form? I have been using the LOV then execute query since I first developing form. But I am building a bigger database recently that I start worrying about multiple query trip to dbms.
    FYI my table will have up to million rows on it. Each row will be very active (updated) within 1-2 weeks after it creation. After that it will exist for records purposes only (select only). The active rows are probably less than 1% of all the rows.

  • Syntax for Update Query?

    Hi
    I have the following query:
    update martin_adhoc_pct
    set adhoc.mbr_oed = mbr.orig_eff_date
    where adhoc.subs_ssn = mbr.subs_ssn
    and adhoc.mbr_type = mbr.mbr_type
    I get an error saying that:
    ORA-000904 "mbr"."mbr_type" invalid identifier..
    I am using PL/SQL and pulled the table name and field directly from the Objects listing so the names are right. This is the first time I've attempted an UPDATE statement with SQL, so wondering what I'm doing wrong..
    Thanks for any help..

    Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production
    I have created a table in our data warehouse that has a blank column (specified as datatype DATE) that I want to update with data from another data warehouse table (one that I didn't create). So for example:
    ssn mbr type oed
    123456789 aab needs to be filled in
    987654321 dd1 needs to be filled in
    etc..
    The unique identifier is the sub id and mbr type, so that's why my code joined these fields between the tables. Where they are equal, fill in the associated oed. I need all rows filled in, not just one. Here is the created table code:
    SELECT  mbr00.mbr_type,
            mbr00.mbr00_subs_ssn,
            me607.subscriber_id,
            cast (null as date) mbr_oed       
    from  odw.member_exp me607,
            odw.member_mas mbr00
    where   me607.subscriber_id = mbr00.mbr00_ssn_ref_num   
    and     me607.elig_start_date < sysdate
    and     me607.elig_end_date > sysdate
    and     me607.rmc_code in ('123')
    {code}
    Thanks..
    Edited by: user12296489 on Feb 11, 2010 9:06 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • What is the best method for updating Bios for 8.1 on GT70 2OD

    Hey,
    I've been getting a bunch of different BSODs and its been recommended I update my bios because I am running win 8.1
    Im just a little confused with which method would be best to update the bios. The EFI bios utility method on the PDF looks easy enough, but the information above that says to use the flash utility in the compressed file. Is that the afuwinx64.exe file and I run it from windows? or can I do something with the .bat files?
    As you can tell I dont know to much about this kind of thing, I have been avoiding this update hoping to solve all issues without it, no such luck unfortunately. The feedback I got said that it seems as If something is misconfigured. in your opinion is it likely not having the bios updated could cause issues?
    Thanks.

    Use one of the methods outlined in the PDF files on the website from MSI. Either of those methods should work just fine.
    The generally recommended method though is using the BIOS HQ Flasher.
    >>Use the MSI HQ Forum USB flasher<<
    I would NOT just flash using the exe or the bat files, as this can cause issues if done improperly.
    I believe there was a bios update for the GE series of laptops because of a configuration issue for Windows 8.1. I don't believe the update for the GT series for Windows 8.1 had that same issue.

  • Lock and semaphore, what's better method for my case

    Hi all,
    I'm implementing a classic case: a consumption queue with infinite capacity. That's say I have a queue of infinity capacity, a thread to put objects into the queue, another thread take it out. Pseudo code is smth like below:
    void put(Object o) {
    put message into the queue
    if (consume thread is waiting) {
    lock();
    signal();
    unlock();
    void eat() {
    if (queue not empty)
    take object out;
    else
    lock;
    wait for signal from producer;
    wake up and take object out;
    unlock;
    I don't know if I should use semaphore or Lock interface to get the job done. Do you know which one is better in my case? I'm writing an apps which is very sensitive in latency so basically I want the eater to get the object as soon as possible. Any advices?
    Message was edited by:
    principles

    Blocking queue doesn't work for me as it is too slow.
    I don't need to lock the data because one thread
    adds too the tail, one thread consumes the head, so
    why bother?LinkedBlockingQueue allows concurrent access to the head and tail ie it uses two different locks.
    A Lock is a mechanism for mutual exclusion. It generally has a notion of ownership and so the thread that locks must be the thread that unlocks.
    A Semaphore is a resource counter. There are no constraints on which thread signals() after await(). It is only a protocol that you establish in your code that allows it to be used for exclusion.
    A bounded-buffer generally needs two synchronization aids:
    a) an exclusion control to ensure the data structure is not corrupted by concurrent access
    b) a coordination control to allow consumers to block when the buffer is empty, or producers to block when the buffer is full.
    These two can be combined by using "synchronized" methods and wait/notify. Or by using Lock and associated Condition objects. Or you can use "synchronized" blocks or Lock for exclusion, and handle the coordination using a seperate semaphore (which must use some form of internal synchronization too - but perhaps more efficient.)
    If you have a lock-free data structure, such as ConcurrentLinkedQueue then you don't need anything for (a) and so you only need coordination. So try using a Semaphore: put() increments it and take() decrements it.
    But the Semaphore still becomes a serialization point in your code.

  • Better method for newspaper editing

    I've been able to make some news articles and export them to PDF with pleasing results and have been improving my efficiency with each completed document, but feel that there is a better way of doing it still.  Basically, what I'm making are articles that have about two to three images embedded in each article, and have maybe two to three jump lines which redirect the reader to other pages. 
    I have about 35 articles total.  Is there a way to enter them all into InDesign, add appropriate images and captions to the articles, and add appropriate jump lines (if there's a way to add meta data to each article and specify a "jump line title" variable that will automatically fill in before "Next Page Number" / "Previous Page Number")?  So that way, I can pick and choose which articles to add to each newsletter volume instead of undertaking the laborious task of adding an article and having to manually edit every component.
    Thx!

    Hey, it sounds like you could use Section Markers. If you name your pages (assuming each article starts on a new page) you can have the section names be filled in automatically. Take at the document numbering options for more information on this: http://help.adobe.com/en_US/indesign/cs/using/WSa285fff53dea4f8617383751001ea8cb3f-7111a.h tml
    Your jump box could look like this: "[SectionMarker] continued on [NextPageNumber]"
    Let me know if you still need help.

  • Proper Method for updating Virtualbox on linux-ck? [SOLVED]

    Running linux-ck on sandybridge, here are installed packages:
    linux-ck-sandybridge 3.19.1-1
    linux-ck-sandybridge-headers 3.19.1-1
    virtualbox 4.3.26-1
    virtualbox-ck-guest-modules-sandybridge 4.3.24-2
    virtualbox-ck-host-modules-sandybridge 4.3.24-2
    virtualbox-ext-oracle 4.3.26-1
    virtualbox-guest-iso 4.3.26-1
    virtualbox-host-dkms 4.3.26-1
    kernel information:
    3.19.1-1-ck #1 x86_64
    After updating Virtualbox, I am receiving this error:
    RTR3InitEx failed with rc=-1912 (rc=-1912)
    The VirtualBox kernel modules do not match this version of VirtualBox. Reload the modules or if you don't use our stock kernel execute
    'dkms autoinstall'
    Which of course would traditionally mean that I must re-compile virtualbox kernel modules. In the old Arch days, that was:
    /etc/rc.d/xbovdrv setup
    I'm a bit confused by both the Virtualbox wiki page as well as the linux-ck page; my understanding is that the linux-ck repo contains updates modules for virtualbox, and that these automatically update (thereby removing the need to use dkms). However, I am fully updated and I am still getting this error (after reloading kernel modules and rebooting).
    I've also tried running:
    dkms install vboxhost/4.3.26
    As root, but it only reports that, "Module vboxhost/4.3.26 already installed on kernel 3.19.1-1-ck/x86_64"
    I'm sure this is my bad, but I'm afraid after two hours of reading the wiki and this forum, I am still quite lost. I'd appreciate any help - let me know if there is anything else I can tell you all that will help!
    Thanks
    Last edited by yochaigal (2015-03-20 14:43:12)

    No idea why your system has /etc/rc.d/* ... if you're using [repo-ck] I have been be compiling 3.19.2 and just rebuilt the vbox packages updating them to 4.3.26.  There was a short delay since I had to rebuild against the new kernel.  Anyway, just:
    pacman -Syyu

  • Help for update query

    Hi, How I can split the column of code_full_desc and update in code1,code2 and code3 column which are blank. It should be split after first hyphen.
    create table #desc (code_full_desc char(20), code1 char(4),code2 char(4), code3 char(6))
    insert into #desc values ('CCCCA_AAAA_99_ECTRA','','','')
    insert into #desc values ('DDDDA_BBBB_88_TRACT','','','')
    ---Results should be
    code_full_desc                  code1   code2   code3
    CCCCA_AAAA_99_ECTRA     AAAA   99        ECTRA
    DDDDA_BBBB_88_TRACT      BBBB    88       TRACT

    create table #desc (code_full_desc char(20), code1 char(4),code2 char(4), code3 char(6))
    insert into #desc values ('CCCCA_AAAA_99_ECTRA','','','')
    insert into #desc values ('DDDDA_BBBB_88_TRACT','','','')
    select * from #desc
    ;with mycte as
    SELECT row_number() Over(Partition by code_full_desc Order by code_full_desc) rn, code_full_desc, S.a.value('(/H/r)[4]', 'VARCHAR(100)') AS splitVal4
    , S.a.value('(/H/r)[3]', 'VARCHAR(100)') AS splitVal3
    , S.a.value('(/H/r)[2]', 'VARCHAR(100)') AS splitVal2
    , S.a.value('(/H/r)[1]', 'VARCHAR(100)') AS splitVal1
    ,code1,code2,code3
    FROM
    SELECT *,CAST (N'<H><r>' + REPLACE(code_full_desc, '_', '</r><r>') + '</r></H>' AS XML) AS [vals]
    FROM #desc) d
    CROSS APPLY d.[vals].nodes('/H/r') S(a)
    Update mycte
    set
    code1=splitVal2,
    code2=splitVal3,
    code3=splitVal4
    WHERE rn=1
    select * from #desc
    drop table #desc

Maybe you are looking for

  • Adobe Reader 11 - An internal error occurred - Mac OS X 10.9.1

    My system is a Mac OS X 10.9.1 which had Adobe Reader working perfectly fine. I have downloaded and installed the NEW Adobe Reader 11 yesterday. Every time I open a PDF from any web browser I get a "An internal error occurred" message and nothing ope

  • Trouble adding comments using Reader X from enabled comments in Acrobat 9

    I am a Technical Writer with Acrobat 9. Regularly I make my documents comment enabled for reader. IT has been updating systems and some of my recipients now have Reader X. Because of the difficulty they have, when they open the commentable PDF they a

  • Drag and drop issue alternatives

    Hello i'm having the same drag and drop issue as the other guys here. basically cant drag and drop to the desktop. Im looking for a workaround that doesnt involve making temporary backups or repairing iphoto libraries. My library is 260gb and even th

  • How can I show 2 fields in a Listbox ?

    In my datatable I have a field "firstname" and a field "lastname". How can I manage to get "firstname lastname" shown in the listbox?

  • My iTunes Match is Hung-Up

    Just purchased iTunes Match, after installation it seems to be stuck in Step 2. attempting to match my music with songs in the iTunes Store.  It has matched 1,740 out of 1,742 songs, but it can't seems to complete the match for the remaining two song