View previous topic :: View next topic
|
Author |
Message |
prav_06 Warnings : 1 Active User
Joined: 13 Dec 2005 Posts: 154 Location: The Netherlands
|
|
|
|
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 |
|
|
vini_srcna
Active User
Joined: 26 May 2005 Posts: 178 Location: Copenhagen, Denmark
|
|
|
|
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 |
|
|
prav_06 Warnings : 1 Active User
Joined: 13 Dec 2005 Posts: 154 Location: The Netherlands
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
prav_06 Warnings : 1 Active User
Joined: 13 Dec 2005 Posts: 154 Location: The Netherlands
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
|