Problem with "SELECT...FOR UPDATE OF..." and "POST command" combination

Problem with "SELECT...FOR UPDATE OF..." and "POST command" combination
Problem in committing transactions in Multiple Forms (Oracle Forms) with POST built-in command:
Consider that the following statements are written in WHEN-WINDOW-CLOSED trigger of a called form.
Statements in called form (Form name: FORM_CHILD):
go_block('display_block') ;
do_key('execute_query') ;
-- Data from table_b will be populated in this block, based on the value of COLUMN_1 obtained
-- from TABLE_A.
-- Example: If the value of COLUMN_1 is 10, then all the matching records from TABLE_B, which
-- are inserted with value 10 in TABLE_B.COLUMN_1 will be fetched and shown here.
if user_choice = 'YES' then
commit ;
else
rollback ;
end if ;
Statements in calling forms:
There are two calling forms having following statements and it is going to call the above said called form.
CALLING FORM 1
Statements in KEY-COMMIT trigger:
post;
call_form(form_child, no_activate) ;
Statements in ON-INSERT trigger:
select column_1
from table_a
for update of column_1
where column_2 = 'X' ;
update table_a
set column_1 = column_1 + 1
where column_2 = 'X' ;
insert into table_b ...;
insert into table_b ...; Statements in KEY-COMMIT trigger:
post;
call_form(form_child, no_activate) ;
CALLING FORM 2:
Statements in ON-INSERT trigger:
select column_1
from table_a
for update of column_1
where column_2 = 'X' ;
update table_a
set column_1 = column_1 + 1
where column_2 = 'X' ;
insert into table_b ...;
insert into table_b ...;
insert into table_b ...;
Our understanding:
Assume that both the forms are running from two different machines/instances, issuing commit at the same time. In this case, forms will start executing the statements written in ON-INSERT trigger, the moment POST command is executed. Though the commit is issued at the same time, according to oracle, only one of the request will be taken for processing first. Assume that calling form 1 is getting processed first.
So, it fetches the value available in COLUMN_1 of TABLE_A and locks the row from further select, update, etc. as SELECT...FOR UPDATE command is used (note that NOWAIT is not given, hence the lock will be released only when COMMIT or ROLLBACK happens) and proceed executing further INSERT statements. Because of the lock provided by the SELECT...FOR UPDATE command, the statements in calling form 2 will wait for the resource.
After executing the INSERT statements, the FORM_CHILD is called. The rows inserted in to TABLE_A will be queried and shown. The database changes will be committed when user closes the window (as COMMIT is issued in its WHEN-WINDOW-CLOSED trigger). Then the SELECT...FOR UPDATE lock will be released and calling form 2's statements will be executed.
Actual happenings or Mis-behavior:
Calling form 2 starts executing INSERT statements instead of waiting for SELECT...FOR UPDATE lock. Also, the value selected from TABLE_A.COLUMN_1 is same in both the calling forms, which is wrong.
The rows inserted into TABLE_B are having similar COLUMN_1 values in calling form 2 and they are fetched and shown in the called form FORM_CHILD.
Note that in calling form 2 also POST only is issued, but the changes posted there are accessible in calling form 1 also, which is wrong.
Kindly suggest us as to how to fix above problem. It will be much use, if you can send us the information regarding the behavior of Oracle Forms POST built-in also.
Our mail ID: [email protected]
Thanks a lot in advance.

You have several problems:
1. On-Insert will ONLY run if you have created a new record in a base-table block. If you haven't done that, then the POST command will not cause it to run.
2. Select for update without a "no wait" will lock records for the first form, but when the second form tries this, it will hit the ORA-00054 exception, and will NOT wait. The only way you could make it wait is to issue an UPDATE sql command, which is not such a good way to go.
All POST does is issues SQL insert or update commands for any changes the user has made to records in a form's base-table blocks, without following with a Commit command.
Also understand that Commit is the same as Commit_Form, and Rollback is the same as Clear_Form. You should read up on these in the Forms help topics.

Similar Messages

  • Trigger with SELECT-FOR-UPDATE

    There is a trigger on a table, which updates a particular column with SYSDATE BEFORE an INSERT OR UPDATE in the table.
    CREATE OR REPLACE TRIGGER my_schema.trg_Order
    BEFORE INSERT OR UPDATE
    ON my_schema.ORDER
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    BEGIN
    :NEW.LAST_UPDATE_DATE := SYSDATE;
    END;
    If I update the record using PL/SQL with SELECT-FOR-UPDATE & then UPDATE, the column LAST_UPDATE_DATE is not updated with the SYSDATE.
    But if it is done by using the UPDATE Statement, then the column LAST_UPDATE_DATE is correctly updated with the SYSDATE.
    Why? How can I ensure that for SELECT-FOR-UPDATE & then UPDATE will also update the LAST_UPDATE_DATE with SYSDATE.

    The Table Order has a BLOB column.

  • Performance problem with selecting records from BSEG and KONV

    Hi,
    I am having performance problem while  selecting records from BSEG and KONV table. As these two tables have large amount of data , they are taking lot of time . Can anyone help me in improving the performance . Thanks in advance .
    Regards,
    Prashant

    Hi,
    Some steps to improve performance
    SOME STEPS USED TO IMPROVE UR PERFORMANCE:
    1. Avoid using SELECT...ENDSELECT... construct and use SELECT ... INTO TABLE.
    2. Use WHERE clause in your SELECT statement to restrict the volume of data retrieved.
    3. Design your Query to Use as much index fields as possible from left to right in your WHERE statement
    4. Use FOR ALL ENTRIES in your SELECT statement to retrieve the matching records at one shot.
    5. Avoid using nested SELECT statement SELECT within LOOPs.
    6. Avoid using INTO CORRESPONDING FIELDS OF TABLE. Instead use INTO TABLE.
    7. Avoid using SELECT * and Select only the required fields from the table.
    8. Avoid nested loops when working with large internal tables.
    9. Use assign instead of into in LOOPs for table types with large work areas
    10. When in doubt call transaction SE30 and use the examples and check your code
    11. Whenever using READ TABLE use BINARY SEARCH addition to speed up the search. Be sure to sort the internal table before binary search. This is a general thumb rule but typically if you are sure that the data in internal table is less than 200 entries you need not do SORT and use BINARY SEARCH since this is an overhead in performance.
    12. Use "CHECK" instead of IF/ENDIF whenever possible.
    13. Use "CASE" instead of IF/ENDIF whenever possible.
    14. Use "MOVE" with individual variable/field moves instead of "MOVE-
    CORRESPONDING" creates more coding but is more effcient.

  • Lock Cascade With Select for UPDATE

    If I had a employee table and a phone table with a parent/child relationship and a primary key constraint on the employee table-will issuing a select for update on the employee also lock the corresponding child rows on the phone table ?
    If not how can I bring this about ?

    You only need two sessions:
    First session: Issue the 'select for update'
    statements for the row(s) in both tables, don't
    rollback or commit
    Second session: try to update a row that you tried to
    lock in the first session (with NOWAIT).
    Thanks. I can try this definitely. A basic question.
    You are asking me to do a join on both the tables right ?
    Not two individual SQL statements ?
    Updating the primary key is known as a Bad Idea (tm).
    The key should never be touched because it should be
    meaningless. When you have a column that holds 'real'
    information it is no candidate for a primary key.
    Rgds,
    GuidoYes I am aware of that. I was just wondering what is the meaning behind this statement from this link ?
    http://www.akadia.com/services/ora_locks_survival_guide.html
    And the exact phrase from that link under the section Referential Integrity Locks (RI Locks)
    "RI constraints are validated by the database via a simple SELECT from the dependent (parent) table in question-very simple, very straightforward. If a row is deleted or a primary key is modified within the parent table, all associated child tables need to be scanned to make sure no orphaned records will result. "
    Thanks again.

  • Inconsistent Locking with Select for Update

    Hi,
    I seem to be having some issues in using SELECT FOR UPDATE and was hoping to get some insight from the Oralce Guru's out there.
    I have a J2EE application, running in WebLogic 8.1.4 using Oralce 9.2.0.1.0.
    The application contains code that requires locking to be done on a specific table with multiple transactions (tx) requesting the same lock. Eg:
    Tx 1: Select * from Zone where Zoneid = 'Zone1' for update (Obtains lock)
    Tx 2: Select * from Zone where Zoneid = 'Zone1' for update (waits)
    Tx 100: Select * from Zone where Zoneid = 'Zone1' for update
    Tx1 commits.
    It appears that the following transactions, i.e. Tx2 - Tx100 do not seem to execute in the order the lock was requested. That is Tx 100 always appears to be the second last transaction to execute, after which some arbitrary transaction between Tx2 - Tx99 will execute after Tx100 has committed.
    This seems to tell me that the lock is not being handed in a FIFO manner and is causing us great pain as our data is not longer consistent.
    Does anyone know how i might be able to trace which transaction is being awarded the lock? Also if anyone has any suggestion on how to troubleshoot/solve this issue, greatly appreciated.
    TIA
    Prem

    Oracle does not have a lock queue/manager at all. The locked status of a record is essentially an attribute of the record itself. It is stored on the datablock header. When a transaction requests a lock and can't get it, and is willing to wait (SELECT FOR UPDATE without NOWAIT), it first spins while waiting for the lock (four times as I recall), then sleeps waiting for the lock. The the more times it sleeps before getting the lock, the longer it will sleep before trying again.
    What is likely happening here is that transaction 100 is still spinning when transaction 1 commits, so checks back more frequently and gets the lock first. The rest get the lock whenever they wake up and noone else has taken the lock.
    If you need the transaction to occur in order, then I do not think you can use Oracle's native locking mechanism. Depending on what exactly you are trying to do, you may want to look at Advanced Queueing, or possibly the built-in package DBMS_LOCK.
    HTH
    John

  • CNN website problems with Comments section. Scroll and post problems

    CNN website, myself and other firefox users can no longer scroll up and down inside a comment when making a post.
    Often you can not post the comment with the 'post' button unless page is reloaded.
    Problem has been occurring for last week or so.
    I have confirmed that other uses on CNN have same problems with firefox.
    Problem doesn't occur when using I.E.8
    Brgds,
    John

    I have this problem with IE 8. I cannot post comments on CNN.com. I thought CNN.com might have disabled my ability to post comments but am not sure if they have that ability. Thanks for your help!

  • Problems With Bridge for Mac - Playlists and Photos

    I have a Sony Xperia Z3, up to date and an updated version of sony bridge for Mac, so there isnt any problems there for a start.
    Firstly, when I syncronise my playlists, all the tracks are present on my phone, however not divided into the playlists I syncronised them in. Theres 1000's of songs, so to recreate the playlists individually is very tedious, is there no way of transferring the songs in their collections, so they can be viewed in the itunes playlists?
    Secondly, I syncronised alot of photos from iPhoto using the app. Lots of photos have turned up with a black picture icon on the phone, I assume corrupt. Other photos have syncronised all distorted. Why is this? Again, there are alot of these so to do it in smaller sets is also tedious, as the app is pretty slow compared to syncronising with itunes and my old iphone.
    Overall, not impressed with bridge for mac, its a pretty unreliable and slow program!

    Hi richardackroyd!
    Sorry to hear about your problems.
    It's hard for me to know exactly what causes the problems.
    Can you please send me the error-logs for both the probems.
    So I can forward them to the development team.
    Here’s how to get error logs from Sony Bridge for Mac:
    1. In BfM, hold the "alt" key down while selecting the "Phone" menu. Select "Clear logs" to remove all old logs and get a clean start
    2. Reproduce the problem you're having, whether it's connecting the phone, importing photos, doing backup...
    3. In BfM, hold the "alt" key down while selecting the ”Xperia” menu. Select "Export logs"
    4. On the computers desktop there should now be a file named "SonyBridgeForMacLogs_[date].zip
    5. PM me a open dropbox link withe the files.
    Best regards
    Fredrik

  • Problem with BAPI_SALESORDER_CHANGE for updating address details

    Hi,
    I am trying to update address details using the bapi BAPI_SALESORDER_CHANGE. I am unable to update. I am populating only the required fields.
    Could anyone tell whats the problem with BAPI?
    Thanks & Regards,
    Yaseen Mahammad.

    Yaseen,
    Do check whether you have passed values to the internal table ORDER_HEADER_INX. You have to pass value to the update field as 'U' and all the fields which you have passed in the header internal table as 'X'.
    and  behave_when_error = 'P'

  • Problem with printout for Mvtype 551 and Collective slip

    Hi there!
    Need some help.
    Well, I have several items and when posting them with 551 in MIGO and check printing active on collective slip (3), the printout does not show any of items.
    When posting it with same MvType 551 and check printing active on other two values (1 or 2), I get 1 printout for every item.
    So, what should I do to have one printout for all items for MvType 551?
    Thanks!

    Hi Ines,
    Go to NACE, select ME (Inventory Mgmt), click on procedures, select Inventory Mgmt, click on control.
    Here you should find an entry for your condition type there should an entry with requirement type having a value, for GR it is 173, so for your case, check which one applies.
    If helpful award points
    Regards,
    Vivek

  • Problems with Selection for Werks from Eine

    Hi all
    I surch for an way to get the Werks for Eine.
    I know
    EKPO
    EKKO-BSTYP
    LFA1
    LFM1
    EKKO
    EKPO
    EKPO
    EKPO
    EBAN
    MT06E
    EINA
    EINE
    EKPO
    KOMP
    But there is no way to select werks.
    a  bit coding
    SELECT  * FROM EINE
    WHERE INFNR = I_EINE-INFNR
    AND   EKORG = I_EINE-EKORG.
    endselect.
    Chris

    Is ok, but ..
    In the LFa1 the Werk is 500
    in the Eine the Werk is 100.
    The would be no result
    Again.
    On with way i can get WErks for the selection from Eine
    SELECT WERKS ..
    FROM LFA1
    INTO IT_LFA1
    WHERE WERKS IN S_WERKS .
    IF SY-SUBRC = 0.
    SELECT * FROM EINE
    FOR ALL ENTRIES IN IT_LFA1
    WHERE INFNR = I_EINE-INFNR
    AND EKORG = I_EINE-EKORG AND
    WERKS IN S_WERKS .
    ENDIF .

  • Pros and  cons  of  select  for  update  clause

    hi,
    Can anybody explain what are the
    pros and cons of select for update clause
    11.2.0.1

    As commented, there are no pros versus cons in this case.
    What is important is to understand conceptually what this do and why it would be use.
    Conceptually, a select for update reads and locks row(s). It is known as pessimistic locking.
    Why would you want to do that? Well, you have a fat client (Delphi for example) and multiple users. When userA updates an invoice, you want that invoice row(s) locked and prevent others from making updates at the same time. Without locking, multiple users updating the same invoice will result in existing updated data being overwritten by old data that also has been updated. A situation called lost updates.
    For web based clients that are stateless, pessimistic locking does not work - as the clients do not have state and pessimistic locking requires state. Which means an alternative method to select for update needs to be used to prevent lost updates. This method is called optimistic locking.
    So it is not about pros versus cons. It is about understanding how the feature/technique/approach works and when to use it.. and when it is not suited to use it. All problems are not nails. All solutions are not the large hammer for driving in nails.

  • Memory Leak - select for update

    Hi All.
    Doing an application using OCI 8.1.7 I faced with a memory leak. (or it seems to). The leak is caused by OCIStmtExecute with SELECT FOR UPDATE statement when the iters parameter of that function is 0. In all other cases it works Ok. Below you can find a code causes a leak:
    const char* sqlStatement = "select integercol from test_types for update";
    OCIStmt* ociStatementHandle = 0;
    OCIHandleAlloc(ociEnvHandle,(dvoid **)&ociStatementHandle,
    OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0));
    OCIStmtPrepare(ociStatementHandle, ociErrorHandle,
    (text*)sqlStatement, strlen(sqlStatement), OCI_NTV_SYNTAX, OCI_DEFAULT));
    int int_test;
    OCIDefine* ociDefineHandle = 0;
    OCIDefineByPos(ociStatementHandle, &ociDefineHandle, ociErrorHandle,
    1, (dvoid *)&int_test, (sword) sizeof(int), SQLT_INT, (dvoid *) 0, (ub2 *)0,
    (ub2 *)0, OCI_DEFAULT));
    ub4 iters = 0; // (0 causes a leak)
    for( int i=0; i < 100000; i++ )
    OCIStmtExecute(ociServiceHandle, ociStatementHandle, ociErrorHandle, iters, (ub4) 0, (CONST OCISnapshot *) NULL, (OCISnapshot *) NULL, OCI_DEFAULT));
    If I change iter to 1 the leak disappears, but it is not suitable of course. Oracle documentation says following:
    iters (IN)
    For non-SELECT statements, the number of times this statement is executed is equal to iters - rowoff.
    For SELECT statements, if iters is non-zero, then defines must have been done for the statement handle. The execution fetches iters rows into these predefined buffers and prefetches more rows depending upon the prefetch row count. If you do not know how many rows the SELECT statement will retrieve, set iters to zero.
    This function returns an error if iters=0 for non-SELECT statements.
    Did somebody face the problem? Do you know how to fix it?
    null

    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Bjorn Engsig ([email protected]):
    Are you saying, that the memory leak disappears if you don't do 'for update' in the query?
    Also, is the memory leak on the client or server side?<HR></BLOCKQUOTE>
    Yes, the leak appeares ONLY for 'select ... for update' statements.
    It is a client side leak, the client is Win2000.
    null

  • When does select for update release locks

    Hello all,
    Does anyone know when Oracle realeases the row locks when a
    select for update is issued?
    Does Oracle realase the row lock at the time when an actual update statement is
    issued for the locked row, or does it wait until a commit statment is executed?
    So for example, can I lock several rows with a select for update clause, and then
    issue update statements as many times as I want on each locked row without
    having to worry about the lock being released until I issue a commit statement.
    Thanks,
    David

    yes.
    The lock is released only when your transaction ends. A transaction can end because of:
    1). Commit.
    2). Rollback.
    3). client disconnects.
    etc. etc...

  • Disallow select for update

    Hi,
    I am making a read only user, with select rights on all of the tables in another scheme. How do I dissalow this user to lock the production table with select for update?
    Regards
    Nico

    Good idea in principle, but there may be more efficient solutions than DISTINCT. Any operation which prevents view merging appears to work (or rather not work) e.g.
    CREATE OR REPLACE VIEW view_name
    AS
       SELECT /*+ NO_MERGE */ column_name
       FROM   table_name;...is sufficient to raise ORA-02014: cannot select FOR UPDATE from view with DISTINCT, GROUP BY, etc. when attempting SELECT ... FOR UPDATE.
    It is important to note though that /*+ NO_MERGE */ could theoretically be ignored by the optimizer - another cheap alternative you might consider would be to reference ROWNUM in the view definition, e.g.
    CREATE OR REPLACE VIEW view_name
    AS
       SELECT column_name
       FROM   table_name
       WHERE  ROWNUM >= 1;

  • VPD problem: select for update on join tables with policy on ref table

    In our application we use VPD. Now we ran into an issue. I will try to explain with EMP and DEPT table.
    EMP table has no VPD attached.
    DEPT table has VPD policy that forbids all updates, but allows select. (Policy returns '1=2' for statement type update.
    This query returns no rows:
    select * from emp join dept using (department_id) for update. This makes sense, because I'm going to update both the tables.
    However:
    select * from emp join dept using (department_id) for update of employee_id also returns no rows. THIS IS WRONG. I'm not going to update dept table.
    Any experience with this. Is this a known limitation ?

    I can see all the rows, because there is no select policy.
    However the point is, that VPD should allow me to update the emp table, because there is no update policy.
    With the 'for update of employee_id' clause, VPD should recognize that I'm not going to update the dept table, but only the emp table. But VPD does not recognize this, but applies the update policy of dept to the statement, making the statement to update no rows.
    (Reason behind my question is ADF Business Components, where you have ViewObjects with Referenced Entities. ADF BC generates this type of statement and now we run into this VDP limitation)

Maybe you are looking for

  • Unable to install Full version of Tiger 10.4 or even any part of it!

    eMac 1.25G 256Mb 80G Combo Ok. Now that I have a full version of Tiger. I am unable to install it. Have done first aid several times to the drive. Done the one pass of Zero's as well as verified the drive. I have tried the installation approx 7x. It

  • Printer won't print alignment page

    I have a new HP Officejet 4500g and am setting it up on a Windows Vista (32 bit) system.  The print is brand new and after I set it up and installed the ink cartridges it asked me to hit 'OK'  to print an alignment page.  It pulled in a piece of pape

  • T520 drivers for Windows

    I have been unable to find any drivers from Lenovo for my new T520 running Windows 7, 64-bit.  When will these drivers be available from Lenovo's website? I've re-installed Windows (Pro instead of Home), but I can hardly use it.  There's no support f

  • Is it possible to query for all marketing doc hits to one account?

    We have been struggling to create one single query that pulls all entries made to a particular revenue account by all marketing documents (in 2007A, PL42). For example, an item may be used on an A/R invoice, A/R, credit memo, A/P invoice, or A/P cred

  • Database started but EM does not update

    Hello: I created a database using dbca. I went to Enterprise Manager and started the database. It gave me this message: The database state has been changed successfully from shutdown to open. Note that the current status on this page gets updated whe