Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups 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: 6966
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: 6966
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 Data replication from multiple Db2 ta... kishpra DB2 1 Mon Mar 27, 2017 9:58 pm
No new posts Getting -504 Cursor Name GTT-ARTS-CUR... Robin Sulsona DB2 2 Fri Mar 17, 2017 1:43 am
No new posts IMS DB-How to update a record (a sing... Nic Clouston IMS DB/DC 9 Thu Mar 09, 2017 4:38 pm
No new posts how to send just 10 rows in a CICS sc... Megha Gupta CICS 5 Thu Feb 23, 2017 6:57 pm
No new posts Join of more than one table dibyendumandal11111 DB2 6 Mon Feb 13, 2017 11:36 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us