Using for update

hii evryone,
I'm retreving rows using for update
select n from r_dummy_1 for update nowait;
I'll update
new session>
I've login thru another session but there I'm able to view the same record with previous value before commiting it .Cant I lock my record from viewing it.????Because the person who had login thru different session may be reading previous value and this may lead to loss of data integrity.

This is one of the fundamental database concepts and you should read through the Oracle docs to completely understand the principles on which Oracle operates.
To keep it short here,
- what you see in another session will be committed, consistent data. This is known as Read-Consistency.
- unless or until you commit changes in one session, you should not be able to see the changes in any other session. If you do see only that will cause data integrity issue.
E.g.:
Assume Table A has got 10 rows before any one logs into the database.
Session 1 - You login and insert 5 records into table A.
In your session you will see a count of 15 records, which you can manipulate however you want before committing the changes.
Session 2 - Another user logs in. You have NOT committed your changes. What if he queries Table A and gets to see 15 records and gets to use those records. While he tries to use those records if you ROLLBACK your session changes imagine the spite of data - this is a serious data integrity issue and is danagerous.
That is why Oracle allows read-consistent access to data. Also unlike other database, Oracle does not block reads from writes.
Study References to start with:
http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/title.htm#BEGIN
or better yet I strongly recommend Tom Kyte's book: Expert One on One Oracle

Similar Messages

  • How to unlock a row if i use FOR UPDATE clause

    In procedure if we use FOR UPDATE clause, it will lock particular row and allow only one client to update whereas other client can only fetch data in the same row at that time.
    My question is when will it unlock the row, what should we do to unlock the row while writing procedure. Take this example here im using FOR UPDATE clause for client_count, when ll it unlock that particular row in this procedure.
    create or replace PROCEDURE newprocedur(inMerid IN VARCHAR2,outCount OUT NUMBER) AS
    CURSOR c1 IS
    select CLIENT_COUNT from OP_TMER_CONF_PARENT where MER_ID = inMerid FOR UPDATE OF CLIENT_COUNT;
    BEGIN
    Open c1;
    loop
    fetch c1 into outCount;
    exit when c1%NOTFOUND;
    outCount:=outCount+1;
    update OP_TMER_CONF_PARENT set CLIENT_COUNT = outCount where current of c1;
    end loop;
    close c1;
    END;

    Hi,
    Basically you are incrementing client_count by 1 , Why you have to fetch row one by one and update? you could just finish that in a single update
    UPDATE OP_TMER_CONF_PARENT
    SET CLIENT_COUNT = CLIENT_COUNT+1
    WHERE MER_ID     = inMerid This will increment client_count of all rows by one for the given mer_id;
    After updating you have to make the changes permanent so that other users will see the changes you have made.
    To lock the row before update you can use same select statement in you cursor
    SELECT CLIENT_COUNT
    FROM OP_TMER_CONF_PARENT
    WHERE MER_ID = inMerid FOR UPDATE OF CLIENT_COUNT;You can further modify the procedure to let other users know if the row is being updated.
    Regards
    Yoonas

  • Using for update clause in VPD(Virtual Private Databases)

    Hi,
    We are using for update clause in our procedure to explicitly lock rows in a particular table as shown below:
    SELECT AMOUNT FROM INTERFACE_TABLE
    INTO T_Amount
    WHERE ROWID = :B1
    FOR UPDATE OF BANK_ACCOUNT_NUM NOWAIT;
    But this statement is giving the following error in VPD:
    ORACLE error 1733 in FDPSTP
    Cause: FDPSTP failed due to ORA-01733: virtual column not allowed here.
    We need to lock rows in that particular table until the commit is issued,so as to prevent the updation of the rows which are being processed.
    Is there any other way in which this can be achieved.
    Thanks & Regards,
    Brahmendra Kashyap

    From the docs, which you didn't read:
    ORA-01733 virtual column not allowed here
    Cause: An attempt was made to use an INSERT, UPDATE, or DELETE statement on an expression in a view.
    Action: INSERT, UPDATE, or DELETE data in the base tables, instead of the view.
    Can you explain why you didn't read the docs? I'm just curious why so many people do absolutely nothing to resolve their problem (they would learn Oracle by doing so) and request to be spoon fed.
    Sybrand Bakker
    Senior Oracle DBA
    Experts: those who did read the documentation.

  • How to lock a row by using 'for update'?

    how to lock a row by using 'for update'?

    Hi,
    SELECT * FROM <TABLE> WHERE <PK_COLUMN>=<VALUE> FOR UPDATE NOWAITThis will help in locking the row with the primary key value that you provide
    cheers
    VT

  • Getting ROWID without using "FOR UPDATE" in statement

    Hi,
    Is there any way to get the ROWID of the current record without using "FOR UPDATE" in the statement?
    Here's the story...
    I'm actually working on a server that receives multiple connections from client applications. The server interacts with OCI for selecting, updating, fetching and so on. The server is able to manage many opened recordset from clients.
    Here's a possible scenario:
    - A client asks the server to open a recordset ie: "SELECT * FROM foo".
    - Then, the server receives a command to position the cursor on the last record ie: "OCIFetch2->LAST".
    - Finally, the client decides to update the current (last) record.
    Since the server can receive other requests such as opening a new recordset from another client, I can't use "SELECT * FROM foo FOR UPDATE" because it blocks further call to OCIStmtExecute (even in NONBLOCKING mode).
    At the same time, I can't COMMIT the transaction after the "SELECT" statement otherwise the selection gets invalidated. The selection needs to remain valid until the client decides to "close the recordset".
    Is there any workaround?
    Any help would be appreciated!
    Thanks,
    Jonathan Primeau
    Software Engineer
    Integration New Media, inc.

    Hi again,
    I found that OCIRowidToChar could save my life. In fact, by retrieving the ROWID equivalent string I could use it to build a statement like:
    update foo set c1 = 1 where rowid = 'AAAHZuAABAAAMViAAL';
    which will solve my problem since these strings don't change and represents a unique record.
    The problem is when I try to compile this method it says:
    test.cpp: In function `sword OpenRecordset(OCIServer*&, OCISvcCtx*&, OCIStmt*&,
    COLDEF*)':
    test.cpp:382: `OCIRowidToChar' undeclared (first use this function)
    test.cpp:382: (Each undeclared identifier is reported only once for each
    function it appears in.)
    make: *** [test] Error 1
    It seems that this function is not declared under Solaris/Oracle 9i. I searched on the web and there is not much information about that. However, it is documented in the Oracle book.
    Is there any way to use this function under Solaris? If not, how can I get the string that represents a ROWID?
    I use the following syntax:
    sword OCIRowidToChar ( OCIRowid *rowidDesc,
    OraText *outbfp,
    ub2 *outbflp
    OCIError *errhp );
    Best regards,
    Jonathan
    Software Engineer
    Integration New Media, inc.

  • Inbound IDoc used for updating Sales order status

    I have a requirements to set use standard IDoc to send out the Sales order to a non-SAP software as well as receiving Inbound IDoc to update the status of sales order in SAP. Could someone comment on my questions below:
    1. What are the difference between all the ORDERSxx Idoc types?
    2. What IDoc should be used for Inbound IDoc to update the sales order stataus in SAP?
    3. Can the same IDoc type be used for both Inbound and Outbound with only the difference in the segment of Direction?
    Thank you. Points will be awarded appropriately for helpful comments.

    Hi,
      1.Intially  standard IDOC types "ORDERS01"  is having limited
          segments. After few months the requirement got increased to
          add more fields to "ORDERS01".So,once you release the IDOC
          type you can not add any more fields .So SAP come up
          with "ORDERS02" with new fields.Like that all IDocs types have
          some more new seg ments.
    2.You  can use ORDER05
    3. Yes you can use same IDOC type

  • BADI used for updation of Amount fields for transaction CL24N

    Hi All,
    Badi's used for the transaction CL24N . Since need to update amount field ZPO_AMOUNT , ZPO_AMOUNT_GBP in the trsaction for a particular Realease strategy
    Thanks,
    Narasimha.

    Hi,
      There are 4 User-Exits and 2 Badis present for that transaction. Check whether it is useful.
    Enhancement/ Business Add-in            Description
    Enhancement
    CLCLRS01                                Additional Fields on the Result Screen
    CLCLRS02                                Fill the Additional Fields on the Result Screen
    CLFM0003                                Call Up After Check of Assigned Characteristic Values
    CLMMD001                                Selection of Objects for Mass Processing
    Business Add-in
    CACL_CHARACTER_INPUT                    Value Assgmt Screen: Set Ready-For-Input Status for Chars
    CACL_VALUE_CHANGE                       Change/Check User Input Before Syntax Check
    Hope this will help.
    Regards,
    Swarna Munukoti.

  • 2 iTunes accounts, unable to change what is used for "updates" on iPad.

    Sorry - this might sound confusing, but I'll try to explain.
    I have 2 iTunes account. My primary Canadian and a US account.
    The US account is only for those situations where I have to redeem a free promo code, etc.
    The problem I'm having is that for normal, every day use my standard account is what I use to download and update applications.
    However now when I try to "Update" apps from the iPad directly, it tries to use my US store account and, since the applications were purchased from my default account, I cannot update them directly on the iPad.
    Updating them on my PC through iTunes works just fine, however.
    I don't know what I need to do to fix this.
    I've signed out everywhere I can on my iPad and signed back into my default account.
    I've done the same through iTunes, I make sure whenever I sync my iPad, I am signed in on my default account.
    Any time I download on the iPad, I generally only use my primary account, and there are no issues with the initial download.
    Any suggestions...??? Did I clarify enough?
    Thanks!

    When you originally set up the iPad did it or does it ask you to log into your iTunes or possibly we're you logged into your US account when you connected your iPad for the 1st time. Have you done a full restore on your iPad...start fresh not a restore from back up.

  • How do I change the apple Id used for updating apps and downloading them

    I bought an iPad from someone and I changed the apple ID but for some reason when I try to update the apps the old apple ID comes up from the previous owner ...........I just need to know how I possibly can change it

    You cannot.  Purchases are permanently tied to the AppleID and its account used when making the purchase.  You cannot transfer purchases.
    The reality is you do not own the apps on that iPad - the previous owner does.  If you want them for yourself and want to be able to update them as needed, or re-download them as needed, you will have to delete the copies on the iPad, then purchase them with your own AppleID.

  • When should SELECT ..FOR UPDATE be used?

    DB Version:10gR2
    This is what 10gR2 PL/SQL documentation says about SELECT...FOR UPDATE
    With the SELECT FOR UPDATE statement, you can explicitly lock specific rows of a
    table to make sure they do not change after you have read them. That way, you
    can check which or how many rows will be affected by an UPDATE or DELETE
    statement before issuing the statement, and no other application can change the
    rows in the meantime
    But i don't see SELECT...FOR UPDATE much in our production codes. Is SELECT ..FOR UPDATE used when huge amount of rows need to be updated?

    Its maily used for locking table with differnt node , commely this concpet where used in
    ERP products, bcoz different user can acces same table at time and do some DML
    operation, using FOR UPDATE will protected ,
    before that read this
    hb venki

  • BADI-User exit required for updating Purchase order header field -IHREZ

    Hello All,
    We have requirement in our business to update the purchase order header field "our reference" EKKO-IHREZ with some text field. We need a BADI/user exit that can be used for updating this field . We have checked the BADI ME_PROCESS_PO_CUST and unfortunately we are not able to use this BADI as it getting triggered in enjoy SAP transactions ME21N , ME22N etc. We are not creating the purchase order manually and we are using ME59N for creating Purchase order . Hence we are looking for some user exit/BADI that can be used in ME59N for updating the purchase order header field IHREZ.
    Thanks in advance for your immediate response .
    With regards,
    Joseph Anand B

    TRY using the exist u2022     EXIT_SAPLME59_001
    You can also later on add this field by BAPI_PO_CHANGE

  • BADI or function module for updating open purchase orders

    Hi all,
    Does anyone know of a BADI or function module which can be used for updating item prices in open purchase orders?
    All helpful answers are highly appreciated!
    Regards,
    MV

    1 ) execute this program  in se38 .enter the input as transaction code  for which you want list of User
    Exit.
    REPORT z_find_userexit NO STANDARD PAGE HEADING.
    *&  Enter the transaction code that you want to search through in order
    *&  to find which Standard SAP® User Exits exists.
    *& Tables
    TABLES : tstc,     "SAP® Transaction Codes
             tadir,    "Directory of Repository Objects
             modsapt,  "SAP® Enhancements - Short Texts
             modact,   "Modifications
             trdir,    "System table TRDIR
             tfdir,    "Function Module
             enlfdir,  "Additional Attributes for Function Modules
             tstct.    "Transaction Code Texts
    *& Variables
    DATA : jtab LIKE tadir OCCURS 0 WITH HEADER LINE.
    DATA : field1(30).
    DATA : v_devclass LIKE tadir-devclass.
    *& Selection Screen Parameters
    SELECTION-SCREEN BEGIN OF BLOCK a01 WITH FRAME TITLE text-001.
    SELECTION-SCREEN SKIP.
    PARAMETERS : p_tcode LIKE tstc-tcode OBLIGATORY.
    SELECTION-SCREEN SKIP.
    SELECTION-SCREEN END OF BLOCK a01.
    *& Start of main program
    START-OF-SELECTION.
    Validate Transaction Code
      SELECT SINGLE * FROM tstc
        WHERE tcode EQ p_tcode.
    Find Repository Objects for transaction code
      IF sy-subrc EQ 0.
        SELECT SINGLE * FROM tadir
           WHERE pgmid    = 'R3TR'
             AND object   = 'PROG'
             AND obj_name = tstc-pgmna.
        MOVE : tadir-devclass TO v_devclass.
        IF sy-subrc NE 0.
          SELECT SINGLE * FROM trdir
             WHERE name = tstc-pgmna.
          IF trdir-subc EQ 'F'.
            SELECT SINGLE * FROM tfdir
              WHERE pname = tstc-pgmna.
            SELECT SINGLE * FROM enlfdir
              WHERE funcname = tfdir-funcname.
            SELECT SINGLE * FROM tadir
              WHERE pgmid    = 'R3TR'
                AND object   = 'FUGR'
                AND obj_name = enlfdir-area.
            MOVE : tadir-devclass TO v_devclass.
          ENDIF.
        ENDIF.
    Find SAP® Modifications
        SELECT * FROM tadir
          INTO TABLE jtab
          WHERE pgmid    = 'R3TR'
            AND object   = 'SMOD'
            AND devclass = v_devclass.
        SELECT SINGLE * FROM tstct
          WHERE sprsl EQ sy-langu
            AND tcode EQ p_tcode.
        FORMAT COLOR COL_POSITIVE INTENSIFIED OFF.
        WRITE:/(19) 'Transaction Code - ',
        20(20) p_tcode,
        45(50) tstct-ttext.
        SKIP.
        IF NOT jtab[] IS INITIAL.
          WRITE:/(95) sy-uline.
          FORMAT COLOR COL_HEADING INTENSIFIED ON.
          WRITE:/1 sy-vline,
          2 'Exit Name',
          21 sy-vline ,
          22 'Description',
          95 sy-vline.
          WRITE:/(95) sy-uline.
          LOOP AT jtab.
            SELECT SINGLE * FROM modsapt
            WHERE sprsl = sy-langu AND
            name = jtab-obj_name.
            FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
            WRITE:/1 sy-vline,
            2 jtab-obj_name HOTSPOT ON,
            21 sy-vline ,
            22 modsapt-modtext,
            95 sy-vline.
          ENDLOOP.
          WRITE:/(95) sy-uline.
          DESCRIBE TABLE jtab.
          SKIP.
          FORMAT COLOR COL_TOTAL INTENSIFIED ON.
          WRITE:/ 'No of Exits:' , sy-tfill.
        ELSE.
          FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
          WRITE:/(95) 'No User Exit exists'.
        ENDIF.
      ELSE.
        FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
        WRITE:/(95) 'Transaction Code Does Not Exist'.
      ENDIF.
    Take the user to SMOD for the Exit that was selected.
    AT LINE-SELECTION.
      GET CURSOR FIELD field1.
      CHECK field1(4) EQ 'JTAB'.
      SET PARAMETER ID 'MON' FIELD sy-lisel+1(10).
      CALL TRANSACTION 'SMOD' AND SKIP FIRST SCREEN.
    2) Second way is to go to transaction code SE93 .enter transaction code click on display.
    There you will see the package. Copy that package name.
    Go to transaction code se84
    Enhancements -customer exits-enhancementsu2014enter package there and execute.
    You will get list of exits.
    3) BAPI for PO change is
    BAPI_PO_CHANGE

  • 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 clause

    Hi all
    in cursor with select for update clause we can reference column list. like
    select.......
    from....
    for update [of column_reference]
    I want to know that what is the use of specifying column nane in for update clause?
    because its main purpose is to lock rows before update or delete, and complete row will be locked not only that column, then what is the use of mentioning it.
    Secondly, I want to know that when we perform dml then automatically locks occur, then why we use for update clause.???
    third,
    when locks occur, when we open cursor or when update or delete???

    If you've got FireFox, you can add tahiti.oracle.com and asktom.oracle.com to the list of search engines you have available in the upper right-hand corner. I can't tell you how addicted I am to that little piece of heaven.
    Justin

  • BAPI for updating Evaluation Group1 field in Asset Master

    Hi,
    The business requirement is to Update the Assets master fields with the current location of the Tools with respect to movement of the material only to be used for assets.
    To keep a track for tools being moved to vendor location or internal company. To know the exact liabilities to the company in terms of Capitals being moved to the vendor or company location.
    For this the movement type of the material will define weather the material is within the Campus or is with the Vendor & update the field  Evaluation Group 1 (ANLA-ORD41)
    Can you please help with which BAPI should be used for updating the evaluation group?
    Thanks

    Hi Anupam
    Would appreciate, if you are not arrogant, while  posting your queries to this Forum.
    You can use the Function Module
    ASSET_MASTERRECORD_MAINTENANCE
    Regards
    Sanil

Maybe you are looking for

  • The system failed to flush data to the transaction log. Corruption may occur.

    We have a windows server 2008 R2 Virtual machine and we are getting the following Warning Event. Event 51 Volmgr The system failed to flush data to the transaction log.  Corruption may occur. Any idea what is wrong with this server? Why this event is

  • Export in Query Ready mode not working in 11.1.2.1

    Hi, I have created a report with 3 grids; Grid 1 - populates employee information, Grid 2 - populates employee salary Grid 3 - calculation of Grid 1 and Grid 2. In Report I am able to see the data, but when I am using the "Export in Query Mode" optio

  • MOVED: 945GCM5-F V2 how to tell if it is the 1333mhz version

    This topic has been moved to Overclockers & Modding Corner. https://forum-en.msi.com/index.php?topic=121879.0

  • IPhone 5 backup & iTunes

    Just noticed today that I cannnot backup my iPhone 5 to iCloud. The last backup was Dec. 12. Also, I cannot access iTunes from my phone to do app updates. This just started today. I did check the iCloud status page and all is green. Any one else noti

  • Portlet.xml

    Is there a way to update the portlet.xml dynamically? That is, add an instance of the portlet using <portlet> tag at runtime to the portlet.xml. Does the portlet container need to be bounced back so that the updates are picked up? Got to know that th