Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Update a table using a cursor

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Update a table using a cursor
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    Post subject: Reply to: Update a table using a cursor
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    Post subject:
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: 6970
Location: porcelain throne

PostPosted: Mon Sep 29, 2008 4:51 pm    Post subject:
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    Post subject:
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: 6970
Location: porcelain throne

PostPosted: Mon Sep 29, 2008 5:49 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts -502 Error - Cursor already open anand jeyapaul DB2 7 Sun Oct 29, 2017 4:22 am
No new posts Update table without cursor Ron Klop DB2 3 Wed Oct 11, 2017 1:06 pm
No new posts Table(Unicode(Graphic) table) loading... muralikrishnan_new DB2 0 Thu Oct 05, 2017 5:10 pm
No new posts Insert a Row_number into table useit DB2 2 Tue Sep 19, 2017 1:07 pm
No new posts how to see when the last read access ... Mike 1304 DB2 1 Tue Sep 12, 2017 7:52 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us