For update cursor with nowait

I have a 'for update' cursor defined with 'NOWAIT'. When soem of teh records that are supposed to be fetched by teh cursor are locked by another user for update..teh pl?SQL script returns
"ORA-00054: resource busy and acquire with NOWAIT specified" error.
If I declare teh cursor with out 'FOR UPDATE' or did NOT put 'NOWAIT' clause, teh script hangs waiting for teh records to be unlocked.
If the user opens a record in the front end (web app) and does not close it.. i can not run the script. Is theer any way to ignore those records that are locked by other users and query only ones that are available as part of the select statement in the cursor.

Optimistic locking implies, essentailly, that you never lock the row. Instead, if you want to update the row, you check all the other columns of the row to see whether they have changed. In other words, you'd do a straight SELECT here and then when you went to UPDATE the data, you'd do
UPDATE <<change some column>>
WHERE col1=<<old col1 value>>
   AND col2=<<old col2 value>>
   AND ...If the update changed 1 row, you're set. If it changed 0 rows, someone had changed the underlying row since you SELECTED it, so you'd have to handle that condition. If it returned an error indicating that someone else had locked the row, you could handle that situation as well. If you just continue on, however, be sure that you know how to identify that this row wasn't updated so you can try to do the update the next time (assuming that makes sense).
If all your applications take the optimistic locking approach, you're pretty much guaranteed that no one else will have teh row locked, so you don't have to handle that state nearly as robustly.
Justin
Distributed Database Consulting, Inc.
www.ddbcinc.com

Similar Messages

  • FOR UPDATE cursor is causing Blocking/ Dead Locking issues

    Hi,
    I am facing one of the complex issues regarding blocking / dead locking issues. Please find below the details and help / suggest me the best approach to ahead with that.
    Its core Investment Banking Domain, in Our Day to day Business we are using many transaction table for processing trades and placing the order. In specific there are two main transaction table
    1)     Transaction table 1
    2)     Transaction table 2
    These both the tables are having huge amount of data. In one of our application to maintain data integrity (During this process we do not want other users to change these rows), we have placed SELECT …………….. FOR UPDATE CURSOR on these two table and we have locked all the rows during the process. And we have batch jobs (shell scripts ) , calling this procedure , we will be running 9 times per day 1 hrs each start at 7:15AM in the morn finish it up in the eve 5PM . Let’s say. The reason we run the same procedure multiple times is, our business wants to know the voucher before its finalized. Because there is a possibility that order can be placed and will be updated/cancelled several times in a single day. So at the end of the day , we will be sending the finalized update to our client.
    20 07 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
    20 08 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
    20 09 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
    20 10 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
    20 11 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
    20 12 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
    20 13 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
    20 14 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
    20 15 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
    20 16 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
    20 17 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
    Current Program will look like:
    App_Prc_1
    BEGIN
    /***** taking the order details (source) and will be populate into the table ****/
    CURSOR Cursor_Upload IS
    SELECT col1, col2 … FROM Transaction table1 t 1, Source table 1 s
    WHERE t1.id_no = t2.id_no
    AND t1.id_flag = ‘N’
    FOR UPDATE OF t1.id_flag;
    /************* used for inserting the another entry , if theres any updates happened on the source table , for the records inserted using 1st cursor. **************/
    CURSOR cursor_update IS
    SELECT col1, col2 … FROM transaction table2 t2 , transaction table t1
    WHERE t1.id_no = t2.id_no
    AND t1.id_flag = ‘Y’
    AND t1.DML_ACTION = ‘U’,’D’ -- will retrieve the records which are updated and deleted recently for the inserted records in transaction table 1 for that particular INSERT..
    FOR UPDATE OF t1.id_no,t1.id_flag;
    BLOCK 1
    BEGIN
    FOR v_upload IN Cursor_Upload;
    LOOP
    INSERT INTO transaction table2 ( id_no , dml_action , …. ) VALUES (v_upload.id_no , ‘I’ , … ) RETURNING v_upload.id_no INTO v_no -- I specify for INSERT
    /********* Updating the Flag in the source table after the population ( N into Y ) N  order is not placed yet , Y  order is processed first time )
    UPDATE transaction table1
    SET id_FLAG = ‘Y’
    WHERE id_no = v_no;
    END LOOP;
    EXCEPTION WHEN OTHER THEN
    DBMS_OUTPUT.PUT_LINE( );
    END ;
    BLOCK 2
    BEGIN -- block 2 starts
    FOR v_update IN Cursor_Update;
    LOOP;
    INSERT INTO transaction table2 ( id_no ,id_prev_no, dml_action , …. ) VALUES (v_id_seq_no, v_upload.id_no ,, … ) RETURNING v_upload.id_no INTO v_no
    UPDATE transaction table1
    SET id_FLAG = ‘Y’
    WHERE id_no = v_no;
    END LOOP;
    EXCEPTION WHEN OTHER THEN
    DBMS_OUTPUT.PUT_LINE( );
    END; -- block2 end
    END app_proc; -- Main block end
    Sample output in Transaction table1 :
    Id_no | Tax_amt | re_emburse_amt | Activ_DT | Id_Flag | DML_ACTION
    01 1,835 4300 12/JUN/2009 N I ( these DML Action will be triggered when ever if theres in any DML operation occurs in this table )
    02 1,675 3300 12/JUN/2009 Y U
    03 4475 6500 12/JUN/2009 N D
    Sample output in Transaction table2 :
    Id_no | Prev_id_no Tax_amt | re_emburse_amt | Activ_DT
    001 01 1,835 4300 12/JUN/2009 11:34 AM ( 2nd cursor will populate this value , bcoz there s an update happened for the below records , this is 2nd voucher
    01 0 1,235 6300 12/JUN/2009 09:15 AM ( 1st cursor will populate this record when job run first time )
    02 0 1,675 3300 12/JUN/2009 8:15AM
    003 03 4475 6500 12/JUN/2009 11:30 AM
    03 0 1,235 4300 12/JUN/2009 10:30 AM
    Now the issues is :
    When these Process runs, our other application jobs failing, because it also uses these main 2 tranaction table. So dead lock is detecting in these applications.
    Solutin Needed :
    Can anyone suggest me , like how can rectify this blocking /Locking / Dead lock issues. I wants my other application also will use this tables during these process.
    Regards,
    Maran

    hmmm.... this leads to a warning:
    SQL> ALTER SESSION SET PLSQL_WARNINGS='ENABLE:ALL';
    Session altered.
    CREATE OR REPLACE PROCEDURE MYPROCEDURE
    AS
       MYCOL VARCHAR(10);
    BEGIN
       SELECT col2
       INTO MYCOL
       FROM MYTABLE
       WHERE col1 = 'ORACLE';
    EXCEPTION
       WHEN PIERRE THEN
          NULL;
    END;
    SP2-0804: Procedure created with compilation warnings
    SQL> show errors
    Errors for PROCEDURE MYPROCEDURE:
    LINE/COL                                                                          ERROR
         12/9        PLW-06009: procedure “MYPROCEDURE” PIERRE handler does not end in RAISE or RAISE_APPLICATION_ERROR
         :)

  • For Update Cursor

    Hi ,
    Can you let me know what happen in this cursoe when we use for update?
    CURSOR TRAN_CUR
    IS
    SELECT TRANSACTION_ID
    ,YEAR_MONTH_DT
    ,SOURCE_CD
    ,INVOICE
    FROM
    TRANSACTION_CONTROL
    WHERE
    NEXT_PROCESS = 'MAP'
    FOR
    UPDATE;
    Thanks in advance,

    Assuming that the cursor is written correctly SQL will lock each row as it is selected. The lock will remain until you do a COMMIT or a ROLLBACK. Normally Oracle will lock rows when you perform DML on them but FOR UPDATE causes the row to be locked when the select occurs.
    FOR UPDATE also has the happy side effect of allowing use of the CURRENT OF predicate in select loops simplifying where clauses; when you say "WHERE CURRENT OF cursor_name" for a FOR UPDATE cursor you will only operate on the current row.
    Now for the unhappy side effects. FOR UPDATE cursors run more slowly than normal cursors because it takes time and effort to lock the rows. Second (and worse) you are locked into one transaction for the entire cursor execution because performing a SELECT after a commit or rollback results in the FETCH OUT OF SEQUENCE error (this is not usually a problem but could result in running out of rollback segments or undo space for newer databases. Its unlikely these days but can happen). Finally, performing DML in one statement (as in insert into/select from) is often faster than performing the select loops with DML inside them anyway.
    I wouldn't use FOR UPDATE unless I really needed the rows locked because of the performance hit.

  • 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 OF NEWEST NOWAIT

    Hi,
    Does anyone know the significance of the following "of newest" within the sql stmt. It is taken from the query "select sql_text from V$sql where sql_id in ('xxxxxxx')" for a given sql_id.
    "FOR UPDATE OF NEWEST NOWAIT"
    Regards,
    Mark.

    "FOR UPDATE OF NEWEST NOWAIT"NEWEST is a column of a SELECTed table.
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_10002.htm#i2130052

  • Help with "select .... for update ... nowait" message

    Hi,
    How can I get the Oracle 10 g2 server return code issued when a cursor attemps to select ... for update nowait
    and modify the control in the pl/sql block accordingly if one row is already involved in a transaction?
    Many thanks
    Edited by: JeanParis on Feb 9, 2009 2:57 AM
    Hi again
    i have done a search and I found ( dated 2004 ):
    it will raise an exception 54. you have to catch it.
    So that means I have to manage the cursor inside an inner block et loop until the lock is released?
    Edited by: JeanParis on Feb 9, 2009 3:02 AM
    Edited by: JeanParis on Feb 9, 2009 3:03 AM

    The thing to be wary of is locking the session for ages. The cliched version of this problem is if the other user has gone to lunch without committing. Do we really want to tie up our user for an uunlimited amount of time?
    So it's a good idea to embed the SLEEP() within a finite loop FOR in in 1..10 (or 5 or whatever) and then fail if we still can't get the lock. That at least allows our user to make a decision on whether to try again or do something else more interesting.
    It becomes even important when the program is an autonomic procedure (batch job, daemon) because they are capable of spinning until the databse gets taken down.
    Cheers, APC
    blog: http://radiofreetooting.blogspot.com

  • How to update data when primary key is set through for update cursor

    Dear friends,
    I have tried to update data in the table through forms using cursor for update and i have given the plsql i have used please help me where i do mistake.
    DECLARE CURSOR EMP IS
    SELECT EMPNO,EMPNAME,FATHERNAME,COMMUNITY,SEX,BILLUNIT,BIRTHDATE,RLYJOINDATE,RETIREMENTDATE
    FROM PRMAEMP WHERE BILLUNIT=:CTRL.BILLUNIT AND SERVICESTATUS='SR'ORDER BY DESIGCODE,SCALECODE
    FOR UPDATE;
    BEGIN
    GO_BLOCK('EMP_DETAILS');
    SYNCHRONIZE;
    FOR I IN EMP
    LOOP
    I.BILLUNIT:=:EMP_DETAILS.BILLUNIT;     
    I.EMPNO:=:EMPNO;
    I.EMPNAME:=:EMPNAME;
    I.FATHERNAME:=:FATHERNAME;
    I.COMMUNITY:=:COMMUNITY;
    I.SEX:=:SEX;
    I.BIRTHDATE:=:BIRTHDATE;
    I.RLYJOINDATE:=:RLYJOINDATE;
    I.RETIREMENTDATE:=:RETIREMENTDATE;
    DOWN;
    END LOOP;
    COMMIT;
    END;
    your help is needed immediately

    DECLARE CURSOR ABC IS
       SELECT EMPNO,
              EMPNAME,
              FATHERNAME,
              COMMUNITY,
              SEX,
              BILLUNIT,
              BIRTHDATE,
              RLYJOINDATE,
              RETIREMENTDATE
    FROM PRMAEMP
    WHERE BILLUNIT=:CTRL.BILLUNIT
    AND SERVICESTATUS='SR'
    ORDER BY DESIGCODE,SCALECODE
    FOR UPDATE OF COMMUNITY;
    V_EMPNO           PRMAEMP.EMPNO%TYPE;
    V_EMPNAME         PRMAEMP.EMPNAME%TYPE;
    V_FATHERNAME      PRMAEMP.FATHERNAME%TYPE;
    V_COMMUNITY       PRMAEMP.COMMUNITY%TYPE;
    V_SEX             PRMAEMP.SEX%TYPE;
    V_BILLUNIT        PRMAEMP.BILLUNIT%TYPE;
    V_BIRTHDATE       PRMAEMP.BIRTHDATE%TYPE;
    V_RLYJOINDATE     PRMAEMP.RLYJOINDATE%TYPE;
    V_RETIREMENTDATE  PRMAEMP.RETIREMENTDATE%TYPE;
    BEGIN
       GO_BLOCK('EMP');
       SYNCHRONIZE;
       OPEN ABC;
       LOOP
          FETCH ABC INTO .... /*yOU NEED TO MENTION YOUR VARIABLES HERE*/;
          UPDATE PRMAEMP
          SET BILLUNIT= :EMP.BILLUNIT,
              EMPNO= :EMPNO,
              EMPNAME= :EMPNAME,
              FATHERNAME= :FATHERNAME,
              COMMUNITY= :COMMUNITY,
              SEX= :SEX,
              BIRTHDATE= :BIRTHDATE,
              RLYJOINDATE= :RLYJOINDATE,
              RETIREMENTDATE= :RETIREMENTDATE
          WHERE CURRENT OF ABC;
          EXIT WHEN ABC%NOTFOUND;
       END LOOP;
       CLOSE ABC;
    END;
    COMMIT;
    END;Cheers
    Sarma.

  • For for updating database with referential integrity

    Hi:
    Here is the essence of the problem:
    I have created an Access database that I want the fire chiefs
    to update. The database is a one to many structure with referential
    integrity set. One fire truck has many capabilities. So if Fort
    Myers has a truck named 'FM101' and it has several capabilities
    such as 1.) pumper, 2.) extrication 3.) Advanced Life Support.
    My problem is how to set up a form to do that. In particular,
    how do I set up the form so that it will allow the fire chiefs to
    input several capabilities at a time for a truck.
    I can build a form showing the truck which was obtained from
    a pick-list. And I can show another field showing a pick-list for
    the capability of that truck (pumper, extrication, ALS, etc). My
    question is how do I set up the form to allow the chiefs to input
    multiple lines for the many capabilities of that one truck? Right
    now I have one input for the truck and one input for the capability
    - but I want to enable the user to input as many capabilities as
    they feel necessary.
    How do I do that?
    thanks

    You put the capabilities in a multi-select box.
    <select name="capabilities" multiple="true">
    <option value="capability1">Capability 1</option>
    </select>

  • Need help to write a query for Update statement with  join

    Hi there,
    The following update statement gives me error as the given table in set statement is invalid. But its the right table .
    Is the statement correct? Please help .
    update (
           select distinct(vpproadside.VEHICLE_CRED_OVERRIDE.vin)            
             from vpproadside.VEHICLE_CRED_OVERRIDE
             join vpproadside.vpp_vehicle
               on vpproadside.vpp_vehicle.vin = vpproadside.VEHICLE_CRED_OVERRIDE.vin
            where VPP_CARRIER_SEQ_NUMBER = 90
              and EXPIRY_DATE = '17-MAR-10'
       set vpproadside.VEHICLE_CRED_OVERRIDE.EXPIRY_DATE = '15-SEP-10';Edited by: Indhu Ram on Mar 12, 2010 1:00 PM
    Edited by: Indhu Ram on Mar 12, 2010 1:22 PM
    Edited by: Indhu Ram on Mar 12, 2010 2:35 PM
    Edited by: Indhu Ram on Mar 15, 2010 8:04 AM
    Edited by: Indhu Ram on Mar 15, 2010 8:06 AM
    Edited by: Indhu Ram on Mar 15, 2010 8:28 AM

    Ask Tom has very good discussion about this, if UPDATE does not work for PK issue, you can use MERGE
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:760068400346785797

  • Lightroom for Rawshooter user with now defunct email address

    As a registered user of Rawshooter Premium 2006 I would very much like to make use of the free Lightroom V1.0 offer. Unfortunately my internet provider stopped providing a service so the email address I am registered with Pixmantec with is no longer valid.
    Does anyone know if I will still be able to get a copy and if so, how?
    Cheers
    Brian

    OK you can ignore this as I have already seen that there will be a FAQ for people who have chnaged email addresses. Duh.
    Cheers
    Brian

  • PL/SQL cursor with FOR UPDATE STATEMENT

    Welcome,
    I have some troubles with cursors. When I try update values in table using cursor i receive ORA-01410 Error : "INVALID ROWID".
    I use code as below:
    ALTER SESSION SET CURRENT_SCHEMA=TEST_SCHEMA;
    DECLARE
    TYPE LogTable_typ IS TABLE OF ADMIN_FILE_LOG%ROWTYPE;
    v_ModuleId KTIMS.ADMIN_FILE_LOG.MODULE_ID%TYPE;
    v_CDR KTIMS.ADMIN_FILE_LOG.CDR_SUCCESS%TYPE;
    CURSOR c1 IS
    SELECT MODULE_ID, cdr_success FROM ADMIN_FILE_LOG
    FOR UPDATE OF CDR_SUCCESS NOWAIT;
    BEGIN
    OPEN c1;
    LOOP
    FETCH c1 INTO v_ModuleId,v_CDR;
    IF v_ModuleId = 'LOAD' THEN
    UPDATE ADMIN_FILE_LOG SET CDR_SUCCESS = 70 WHERE CURRENT OF c1;
    END IF;
    EXIT WHEN c1%NOTFOUND;
    END LOOP;
    EXCEPTION
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE(SQLERRM || SQLCODE);
    END;
    When I use ROWID in cursor declaration all works fine.Working code is:
    ALTER SESSION SET CURRENT_SCHEMA=KTIMS;
    DECLARE
    TYPE LogTable_typ IS TABLE OF ADMIN_FILE_LOG%ROWTYPE;
    v_ModuleId KTIMS.ADMIN_FILE_LOG.MODULE_ID%TYPE;
    v_CDR KTIMS.ADMIN_FILE_LOG.CDR_SUCCESS%TYPE;
    v_id ROWID;
    CURSOR c1 IS
    SELECT MODULE_ID, cdr_success, ROWID FROM ADMIN_FILE_LOG
    FOR UPDATE OF CDR_SUCCESS NOWAIT;
    BEGIN
    OPEN c1;
    LOOP
    FETCH c1 INTO v_ModuleId,v_CDR,v_id;
    IF v_ModuleId = 'LOAD' THEN
    UPDATE ADMIN_FILE_LOG SET CDR_SUCCESS = 70 WHERE ROWID = v_id;
    END IF;
    EXIT WHEN c1%NOTFOUND;
    END LOOP;
    EXCEPTION
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE(SQLERRM || SQLCODE);
    END;
    What is difference in this two cases ?
    I try to find this in Oracle documentation "Database PL/SQL User's Guide and Reference" ( http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/sqloperations.htm#i45288 ).
    Please help.

    Hi,
    I think the USE of NOWAIT clause in cursor for update is, to remove the lock immediately after the transaction is over.
    In the second example where you are fetching the rowid explicitly and use the same id in loop to make the update, so there should not be any problem in this case.
    In the first example when you are using CURRENT OF to do the update, it is basically work on basis of latest fetched row from cursor and do the update (but i think implicitly it use the reference of row id also).
    I am not sure about it , but still try once by removing the NOWAIT clause from your cursor for update and try once , see whether you are still facing the error or not.

  • The Cursor's "For Update " and " Where Current of C1" Error in Form9i

    Hi,
    I use a cursor with for update statement. And after it, I update the table with "where current of", then it cause the forms hanged up. But In form50 of dp2k, I can run the form successfully.
    The following source code are written in a Key-Next-Item
    Please help me with the problem!!!!!
    declare
    v_cash date;
    v_entno varchar2(16);
    Cursor c1 is
    select proc_date,entno from loan_bank for update;
    begin
    open c1;
    loop
    fetch c1 into v_cash,v_entno;
    exit when c1%NOTFOUND;
    update loan_bank set proc_date=sysdate where current of c1;
    end loop;
    commit;
    close c1;
    show_alert_info('OK! Done to Proc Date');
    end;

    Hello there,
    I'm also facing the same problem...
    Have you found any solution or work-around yet?
    The code i'm using is the following:
    IS
    CURSOR cur_autonum
    IS
    SELECT an_nr + 1
    FROM autonum
    WHERE an_kode ='ADV'
    FOR UPDATE OF an_nr NOWAIT
    RECORD_NOT_FOUND EXCEPTION;
    RECORD_IS_LOCKED EXCEPTION;
    PRAGMA EXCEPTION_INIT(RECORD_IS_LOCKED,-54);
    BEGIN
    OPEN cur_autonum;
    FETCH cur_autonum INTO :ptperson.pe_nr;
    IF cur_autonum%FOUND
    THEN
    UPDATE autonum
    SET an_nr = :ptperson.pe_nr
    WHERE CURRENT OF cur_autonum;
    CLOSE cur_autonum;
    ELSE
         CLOSE cur_autonum;
         RAISE RECORD_NOT_FOUND;
    END IF;
    EXCEPTION
    WHEN RECORD_NOT_FOUND
    THEN
    :global.rc := fnc_alert(118);
    clear_record;
    previous_record;
    RAISE Form_Trigger_Failure;
    WHEN RECORD_IS_LOCKED
    THEN
    IF cur_autonum%ISOPEN
    THEN
    CLOSE cur_autonum;     
    END IF;
    :global.rc := fnc_alert(119);
    clear_record;
    previous_record;
    RAISE Form_Trigger_Failure;
    WHEN OTHERS
    THEN
    IF cur_autonum%ISOPEN
    THEN
    CLOSE cur_autonum;     
    END IF;
    RAISE;
    END;
    greetings,
    Emiel

  • My cursor for update doesn't work:(

    hi, i have code:
    create or replace procedure szkodowosc_STMT_WC is
         date_do    varchar2(8);
         v_data_b1              szkod_wc_blokady_Wc_07.Data_Przetw%TYPE;
         v_data_b2              szkod_wc_blokady_Wc_07.Data_Przetw%TYPE;
         v_data_b3              szkod_wc_blokady_Wc_07.Data_Przetw%TYPE;
         v_brak_blokady         szkod_wc_blokady_Wc_07.Szkodowosc_Procent%TYPE;
         v_blokada_all          szkod_wc_blokady_Wc_07.Szkodowosc_Procent%TYPE;
         v_blokada_za_miesiac   szkod_wc_blokady_Wc_07.Szkodowosc_Procent%TYPE;
         CURSOR cur_szkod_brak_blokady IS
                select data_przetw, szkodowosc_procent
                from szkod_wc_blokady_Wc_07
                where grupa_porownanie = 'brak blokady'
                order by data_przetw;
         CURSOR cur_szkod_blokada_all IS
                select data_przetw, szkodowosc_procent
                from szkod_wc_blokady_Wc_07
                where grupa_porownanie = 'blokada all'  -- blokada od pierwszego stmt
                order by data_przetw;
         CURSOR cur_szkod_blokada_za_miesiac IS
                select data_przetw, szkodowosc_procent
                from szkod_wc_blokady_Wc_07
                where grupa_porownanie = 'blokada za miesiac'    -- blokada od drugiego stmt
                order by data_przetw;
         CURSOR cur_update IS
                select data_przetw, blokada_all
                from SZKOD_WC_BLOKADY_WC_07_results
                for update of blokada_all NOWAIT;    
    begin
    -- select * from szkod_wc_blokady_Wc_07
    delete from SZKOD_WC_BLOKADY_WC_07_results;
    commit;
    -- przetwarzanie, brak blokady
    OPEN cur_szkod_brak_blokady;
       LOOP
          FETCH cur_szkod_brak_blokady INTO v_data_b1, v_brak_blokady;
          EXIT WHEN cur_szkod_brak_blokady%NOTFOUND;
          INSERT INTO SZKOD_WC_BLOKADY_WC_07_results (data_przetw, Brak_Blokady) VALUES (v_data_b1, v_brak_blokady);
       END LOOP;
       COMMIT;
       EXCEPTION
       WHEN OTHERS
       THEN
          DBMS_OUTPUT.PUT_LINE(SQLERRM);             -- dodac wyrzucanie logow do pliku txt
          ROLLBACK;
    CLOSE cur_szkod_brak_blokady;
    OPEN cur_szkod_blokada_all;
    OPEN cur_update;
       LOOP
          FETCH cur_szkod_blokada_all INTO v_data_b2, v_blokada_all;
          EXIT WHEN cur_szkod_blokada_all%NOTFOUND;
          FOR rec IN cur_update
          LOOP
              IF rec.data_przetw = v_data_b2
              THEN
                  UPDATE SZKOD_WC_BLOKADY_WC_07_results
                  SET blokada_all = v_blokada_all
                  WHERE CURRENT OF cur_update;
              END IF;   
          END LOOP;     
          COMMIT;
       END LOOP;
    CLOSE cur_update;
    CLOSE cur_szkod_blokada_all;
    -- select * from SZKOD_WC_BLOKADY_WC_07_results
    end;my cur_update should update column blokada_all in SZKOD_WC_BLOKADY_WC_07_results table, but i have still NULLs here, why?
    my table after update looks like:
    DATA_PRZETW     BRAK_BLOKADY     BLOKADA_ALL     BLOKADA_ZA_MIESIAC
    2009-08-14     0,362          
    2009-08-21     0,406          
    2009-08-28     0,462          
    2009-09-04     0,509          
    2009-09-11     0,573          
    2009-09-18     0,608          
    2009-09-25     0,645          
    2009-10-02     0,68          
    2009-10-09     0,763          
    2009-10-16     0,852          
    2009-10-23     0,935          
    2009-10-30     1,059          
    2009-11-06     1,148          
    2009-11-13     1,343          
    2009-11-20     1,442          
    2009-11-27     1,554          
    2009-12-04     1,583          
    2009-12-11     1,707          
    2009-12-18     1,807          
    2009-12-25     1,878          
    2010-01-01     1,955          
    2010-01-08     2,086          
    2010-01-15     2,136          
    2010-01-22     2,361          
    2010-01-29     2,469          
    2010-02-05     2,549

    looking at your code (it's quite hard to follow with these table name - probably because I don't understand them), your procedure might look like
    create or replace procedure szkodowosc_STMT_WC is
    begin
       INSERT INTO SZKOD_WC_BLOKADY_WC_07_results
       select data_przetw, szkodowosc_procent
                from szkod_wc_blokady_Wc_07
                where grupa_porownanie = 'brak blokady'
                order by data_przetw;
        UPDATE SZKOD_WC_BLOKADY_WC_07_results r
                  SET blokada_all = (select szkodowosc_procent
                from szkod_wc_blokady_Wc_07 b
                where grupa_porownanie = 'blokada all'
                and b.data_przetw = r.data_przetw
    end;But it probably can be condensed even further by removing the UPDATE, hope you get the gist. :)

  • Error occuring in SELECT statement FOR UPDATE when using WITH cluase

    Hi,
    Iam using oracle 11g version
    Iam having a query with fetch records for update insid with cluase as
    cursor c1 is
    With abc as (
    SELECT col1,col2 from table1, table2 where < condition>
    for update of <col1> skip locked
    select * from abc,table3 where <condition>
    union all
    select * from table4 where id not in (select * from abc)
    if i add "for update of <col1> skip locked" this cluase
    iam getting error ORA-00907: missing right parenthesis
    when i remove "for update of <col1> skip locked" the block is working fine..
    can i know why error is occuring i

    Hi, first of all, your placing of "for update" clause is wrong. It should be at the end like:
    With abc as (
    SELECT col1,col2 from table1, table2 where < condition>
    select * from abc,table3 where <condition>
    union all
    select * from table4 where id not in (select * from abc)
    for update of <col1> skip locked;Second, if you try to compile it with this syntax then you will get a new error.
    ORA-01786:     FOR UPDATE of this query expression is not allowed
    Cause:     An attempt was made to use a FOR UPDATE clause on the result of a set expression involving GROUP BY, DISTINCT, UNION, INTERSECT, or MINUS.
    Action:     Check the syntax, remove the FOR UPDATE clause, and retry the statement.So, you will not be successful with the union clause in your query.

  • Cursor have for update clause

    Hi all,
    Can any one please tell me,what is main use of for update cursor.in which case we are using this clause.with simple example can any one please explain.
    Thanks,
    K.venkata Sanjeeva Rao.

    user13483989 wrote:
    Can any one please tell me,what is main use of for update cursor.in which case we are using this clause.with simple example can any one please explain.Where you are looping through data for some reason and want to update the current row.
    Simple example...
    SQL> select * from emp;
         EMPNO ENAME      JOB              MGR HIREDATE                    SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 17-DEC-1980 00:00:00        800                    20
          7499 ALLEN      SALESMAN        7698 20-FEB-1981 00:00:00       1600        300         30
          7521 WARD       SALESMAN        7698 22-FEB-1981 00:00:00       1250        500         30
          7566 JONES      MANAGER         7839 02-APR-1981 00:00:00       2975                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-1981 00:00:00       1250       1400         30
          7698 BLAKE      MANAGER         7839 01-MAY-1981 00:00:00       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-1981 00:00:00       2450                    10
          7788 SCOTT      ANALYST         7566 19-APR-1987 00:00:00       3000                    20
          7839 KING       PRESIDENT            17-NOV-1981 00:00:00       5000                    10
          7844 TURNER     SALESMAN        7698 08-SEP-1981 00:00:00       1500          0         30
          7876 ADAMS      CLERK           7788 23-MAY-1987 00:00:00       1100                    20
          7900 JAMES      CLERK           7698 03-DEC-1981 00:00:00        950                    30
          7902 FORD       ANALYST         7566 03-DEC-1981 00:00:00       3000                    20
          7934 MILLER     CLERK           7782 23-JAN-1982 00:00:00       1300                    10
    14 rows selected.
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    cursor cur_emp is
      3      select empno, ename, comm
      4      from emp
      5      for update;
      6  begin
      7    for e in cur_emp
      8    loop
      9      dbms_output.put_line('('||e.empno||') '||e.ename);
    10      if e.comm is null then
    11        update emp
    12        set comm = 0
    13        where current of cur_emp;
    14        dbms_output.put_line('-- Commission reset to 0');
    15      else
    16        dbms_output.put_line('-- Commission: '||e.comm);
    17      end if;
    18    end loop;
    19* end;
    SQL> /
    (7369) SMITH
    -- Commission reset to 0
    (7499) ALLEN
    -- Commission: 300
    (7521) WARD
    -- Commission: 500
    (7566) JONES
    -- Commission reset to 0
    (7654) MARTIN
    -- Commission: 1400
    (7698) BLAKE
    -- Commission reset to 0
    (7782) CLARK
    -- Commission reset to 0
    (7788) SCOTT
    -- Commission reset to 0
    (7839) KING
    -- Commission reset to 0
    (7844) TURNER
    -- Commission: 0
    (7876) ADAMS
    -- Commission reset to 0
    (7900) JAMES
    -- Commission reset to 0
    (7902) FORD
    -- Commission reset to 0
    (7934) MILLER
    -- Commission reset to 0
    PL/SQL procedure successfully completed.
    SQL> select * from emp;
         EMPNO ENAME      JOB              MGR HIREDATE                    SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 17-DEC-1980 00:00:00        800          0         20
          7499 ALLEN      SALESMAN        7698 20-FEB-1981 00:00:00       1600        300         30
          7521 WARD       SALESMAN        7698 22-FEB-1981 00:00:00       1250        500         30
          7566 JONES      MANAGER         7839 02-APR-1981 00:00:00       2975          0         20
          7654 MARTIN     SALESMAN        7698 28-SEP-1981 00:00:00       1250       1400         30
          7698 BLAKE      MANAGER         7839 01-MAY-1981 00:00:00       2850          0         30
          7782 CLARK      MANAGER         7839 09-JUN-1981 00:00:00       2450          0         10
          7788 SCOTT      ANALYST         7566 19-APR-1987 00:00:00       3000          0         20
          7839 KING       PRESIDENT            17-NOV-1981 00:00:00       5000          0         10
          7844 TURNER     SALESMAN        7698 08-SEP-1981 00:00:00       1500          0         30
          7876 ADAMS      CLERK           7788 23-MAY-1987 00:00:00       1100          0         20
          7900 JAMES      CLERK           7698 03-DEC-1981 00:00:00        950          0         30
          7902 FORD       ANALYST         7566 03-DEC-1981 00:00:00       3000          0         20
          7934 MILLER     CLERK           7782 23-JAN-1982 00:00:00       1300          0         10
    14 rows selected.Though, of course this is a pointless example as a simple single update would achieve the same. It's more useful if there are 'other things' you need to do with the data that would exceed the capabilities of just using SQL. Personally I've had little need to use this sort of construct.

Maybe you are looking for

  • Files NOT deleted from hard drive

    iTunes will not send files to my recycle bin, only from remove them from my library. I have 2 computers with 7.0.2.16 running. One will ask me if I want to move files to my recycle bin, which it will then do. The other won't ask and won't delete them

  • Making a PDF Form Fillable & Saveable

    I have a form that I need to have made fillable and be able to save the form. I have the form on my computer and it was created with Acrobat. However, I am not able to save the form with the information I type into fields. I need to correct this.

  • How can I get the camera type of a photo?

    I want to select photos according to camera type using AplleScript. How can I get this information? (I used 'properties' but did not succed in selecting one out of the 24 items.) Hans

  • Batch rename files

    How can I batch rename files to original (embedded in metadata) file names?

  • Duplicate and triplicate e-mails

    Hello everyone, Sorry if I'm in the wrong forum. I am at wits end trying to figure out how to avoid or stop duplicate, triplicate and sometimes even four times receipt of the same e-mail from everyone, whether they are in my address book or not. My s