View previous topic :: View next topic
|
Author |
Message |
simha_it
New User
Joined: 05 May 2005 Posts: 30
|
|
|
|
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 |
|
|
gylbharat
Active Member
Joined: 31 Jul 2009 Posts: 565 Location: Bangalore
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
simha_it
New User
Joined: 05 May 2005 Posts: 30
|
|
|
|
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 |
|
|
simha_it
New User
Joined: 05 May 2005 Posts: 30
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
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 |
|
|
gylbharat
Active Member
Joined: 31 Jul 2009 Posts: 565 Location: Bangalore
|
|
|
|
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 |
|
|
|