IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

FOR UPDATE clause in select statement


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
simha_it

New User


Joined: 05 May 2005
Posts: 30

PostPosted: Thu Jul 21, 2011 10:45 am
Reply with quote

Hi,

Could you please tell me, is it possible to use FOR UPDATE clause in single select statement (not in Cursor)?

For: Selete emp-name from Emp-table where Emp-no = 1234 FOR UPDATE;

When I tried to use it in a program I am getting compilation error. Please help me out in this.
Back to top
View user's profile Send private message
gylbharat

Active Member


Joined: 31 Jul 2009
Posts: 565
Location: Bangalore

PostPosted: Thu Jul 21, 2011 11:01 am
Reply with quote

Yes it is possible to use FOR UPDATE outside the cursor.. provided the select statement fetches only 1 row.

I think compilation error is because of something else... Can you post the exact error...
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Jul 21, 2011 11:01 am
Reply with quote

Hello,

Are you getting a compilaton error or a db2 pre-compile error?

Which error(s) are being shown?

I suspect part of your problem is the syntax is simply incorrect. Would you not use:
Code:
  UPDATE tbl
  SET whatever
  WHERE. . . .
Back to top
View user's profile Send private message
simha_it

New User


Joined: 05 May 2005
Posts: 30

PostPosted: Thu Jul 21, 2011 12:38 pm
Reply with quote

I am not writing a seperate Update query or not using any cursor. I have a simple select statement in which I want to use FOR UPDATE clause.

What I amtrying to do here is... I am retrieving a single row (say reference number) using select statement from one table (not locking the table here) and assigning that reference num to one customer who read that row recently.
but 2 customers can access the same row (bcoz it is not locked) and same reference number will be assigned to 2 customers. So, to avoid this situation I want to use FOR UPDATE clause in the select stament to lock the table if any customer is accessing that table. I hope it is clear now.
Back to top
View user's profile Send private message
simha_it

New User


Joined: 05 May 2005
Posts: 30

PostPosted: Thu Jul 21, 2011 12:43 pm
Reply with quote

gylbharat wrote:
Yes it is possible to use FOR UPDATE outside the cursor.. provided the select statement fetches only 1 row.

I think compilation error is because of something else... Can you post the exact error...


could you please provide me the syntax how to use FOR UPDATE in simple Select statement.

exact error msg: "FOR UPDATE OF" CLAUSE NOT PERMITTED
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Jul 21, 2011 3:30 pm
Reply with quote

Quote:
could you please provide me the syntax how to use FOR UPDATE in simple Select statement.


you can't. a singleton select is a select.
and update is an update (see post from the Baker St inhabitant for correct syntax).

now, on to your problem:

Quote:
What I amtrying to do here is... I am retrieving a single row (say reference number) using select statement from one table (not locking the table here) and assigning that reference num to one customer who read that row recently.


people have been successfully coding solutions to insure that no two online tasks receive the same number.
if you would take the time to explain what it is that you are trying to do,
(say reference number - does not get it.)
someone can provide a suggestion.

OH, and the next time we ask for the error code, give us the error code,
not the explanation.................
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Thu Jul 21, 2011 6:31 pm
Reply with quote

gylbharat wrote:
Yes it is possible to use FOR UPDATE outside the cursor.. provided the select statement fetches only 1 row.
Are you sure about that?
Back to top
View user's profile Send private message
gylbharat

Active Member


Joined: 31 Jul 2009
Posts: 565
Location: Bangalore

PostPosted: Thu Jul 21, 2011 7:03 pm
Reply with quote

Marso wrote:
gylbharat wrote:
Yes it is possible to use FOR UPDATE outside the cursor.. provided the select statement fetches only 1 row.
Are you sure about that?


It is possible when we are running query in QMF. I tried this in cobol program but it failed... So this is not possible in an embedded sql.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Dynamically pass table name to a sele... DB2 2
No new posts SELECT from data change table DB2 5
No new posts Select two different counts from SQL... DB2 6
No new posts To search DB2 table based on Conditio... DB2 1
No new posts JOIN STATEMENT PERFORMANCE. DFSORT/ICETOOL 12
Search our Forums:

Back to Top