If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > For update of

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-13-10, 09:50
DBFinder DBFinder is offline
Registered User
 
Join Date: Sep 2008
Location: Toronto,Canada
Posts: 606
For update of

Greetings,

While studying code for some minor issue, I came across this select statement in a java script. This has surprised me, It does not seem to use a cursor.

I tend to believe that I may not know, or I may have not used select this way.

Can some one help me understand why FOR UPDATE OF was used in this statement ?

SELECT * FROM Client_Acc WHERE Acc_Num = ? FOR UPDATE OF Cash_Amt,Real_Chips,Promo_Chips

Help is appreciated. (searched online , all belong to cursor def).

Regards

DBFinder
Reply With Quote
  #2 (permalink)  
Old 07-13-10, 10:12
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
That is used to obtain an IX (intent exclusive) lock on the row which means that no one else can obtain another IX lock, nor an X lock, but others can get a S (share) lock. The lock is released when a commit or rollback is issued.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 07-14-10, 05:21
przytula_guy przytula_guy is offline
Registered User
 
Join Date: Apr 2006
Location: Belgium
Posts: 1,159
__________________
Best Regards, Guy Przytula
Database Software Consultant
DB2 UDB LUW Certified V7-V8-V9-V9.7 DB Admin - Dprop..
Information Server Datastage Certified
http://www.infocura.be
Reply With Quote
  #4 (permalink)  
Old 07-14-10, 05:29
DBFinder DBFinder is offline
Registered User
 
Join Date: Sep 2008
Location: Toronto,Canada
Posts: 606
Thanks


DBFinder
Reply With Quote
  #5 (permalink)  
Old 07-14-10, 08:23
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
Quote:
Originally Posted by przytula_guy View Post
That doc does not tell the whole story. FOR UPDATE can be used without a cursor and is often used to obtain a lock as I described above (while the application examines the contents of row in a select and does not want any others to update it, but want others to be able to read it).

Also, it can be used for a positioned DELETE (in addition to UPDATE).
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #6 (permalink)  
Old 07-14-10, 08:59
przytula_guy przytula_guy is offline
Registered User
 
Join Date: Apr 2006
Location: Belgium
Posts: 1,159
or if you have problems with locking - look at optimistic locking in the doc..
__________________
Best Regards, Guy Przytula
Database Software Consultant
DB2 UDB LUW Certified V7-V8-V9-V9.7 DB Admin - Dprop..
Information Server Datastage Certified
http://www.infocura.be
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On