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

Update a table using a cursor


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

Active User


Joined: 13 Dec 2005
Posts: 154
Location: The Netherlands

PostPosted: Mon Sep 29, 2008 12:14 am
Reply with quote

Dear All,
Am currently having a requirement to update a table using a cursor, a brief description of this would be , consider a table that has two columns say emp.name and parking.slot and lets keep the table name as tab1

First I have to find those employees having the same parking slot, eg

EmpName Slot
Ram 20
Rahul 20
vinay 30
Vj 30

And I have to update the table in such a way that each person has a unique parking slot, for the same I had designed by cursor as given below

declare emp_curs cursor with hold for
select a.empname, a.slot from
tab1 a,
tab1 b
where a.empname <> b.empname and
a.slot = b.slot
order by empname
for update of slot;

My precompilation went fine, but during my bind I get s-203 as sql code, my question is
1.can we go for an update of the cursor when its picked up in a self join?
2.Is there a better query that I can use in my cursor, than the one am currently using ?

Please let me know
Thanks in advance

Regards,
Thamilzan.
Back to top
View user's profile Send private message
vini_srcna

Active User


Joined: 26 May 2005
Posts: 178
Location: Copenhagen, Denmark

PostPosted: Mon Sep 29, 2008 10:53 am
Reply with quote

The cursor is not an updatable cursor. Select query cannot have ORDER BY, GROUP BY, JOINS etc in order to be updatable.
Back to top
View user's profile Send private message
prav_06
Warnings : 1

Active User


Joined: 13 Dec 2005
Posts: 154
Location: The Netherlands

PostPosted: Mon Sep 29, 2008 1:16 pm
Reply with quote

Hi ,

thanks a lot for the reply, is there any other way that I can design the cursor so that It can be updated ??

Thanks

Thamilzan
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Sep 29, 2008 4:51 pm
Reply with quote

suggest you design:
a read only cursor that allows you to ORDER BY PARKING-SLOT;
have an available parking slot table or what ever
and do singleton updates to the employee parking slot.


why order by employee name? the parking slot is what is duplicated.
Back to top
View user's profile Send private message
prav_06
Warnings : 1

Active User


Joined: 13 Dec 2005
Posts: 154
Location: The Netherlands

PostPosted: Mon Sep 29, 2008 5:19 pm
Reply with quote

Hi dbzTHEdinosauer,

Thanks alot for the reply. If am fetching the rows from a read only cursor and I go for an update, it won't bother the master cursor data right ?? I believe it won't but can this be confirmed

Regards,
Thamilzan.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Sep 29, 2008 5:49 pm
Reply with quote

yes, by testing.

without using sensitive cursors or scrollable cursors (not sure which one prohibits) you can do singleton inserts that affect the results of an active cursor.

but, back to your question.

if you do a fetch, then update the row with a singleton select, then you would have to re-fetch the row from your cursor to see if any changes are reflected.
in your case it is a non-issue: you are not updating rows that you have not fetched.
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 Load new table with Old unload - DB2 DB2 6
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Check data with Exception Table DB2 0
No new posts Dynamically pass table name to a sele... DB2 2
Search our Forums:

Back to Top