|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Oracle provides the FOR UPDATE clause in SQL syntax to allow the developer to lock a set of Oracle rows for the duration of a transaction. The FOR UPDATE clause is generally used in cases where an online system needs to display a set of row data on a screen and they need to ensure that the data does not change before the end-user has an opportunity to update the data. However, the FOR UPDATE clause in SQL will cause the SQL to “hang” if one of the requested rows is locked by another user. If you try to access the rows with the NOWAIT clause, you will get an error message, ORA-00054 Resource busy and acquire with NOWAIT specified. Essentially, the options were either “wait forever” or “don’t wait. Oracle has added additional flexibility to the syntax by allowing the SQL to wait for a pre-defined amount of time for locked rows before aborting. In this example we select a student row and wait up to 15 seconds for another session to release their lock: select student_last_name from student where student_id = 12345 FOR UPDATE WAIT 15; In the real-world, many large online systems do not use the FOR UPDATE clause. Rather, they ensure data integrity by re-reading the data when the end-user requests a change, and displays an error message if the data has changed since it was initially displayed to the user. If you like Oracle tuning, you might enjoy my latest book “Oracle Tuning: The Definitive Reference” by Rampant TechPress. It’s only $41.95 (I don’t think it is right to charge a fortune for books!) and you can buy it right now at this link: http://www.rampant-books.com/book_2003_1_oracle9i_sga.htm
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Copyright © 1996 - 2009 by
Burleson Enterprises, Inc. All rights reserved.
Oracle® is the registered trademark
of Oracle Corporation. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||