- 03-10-2010 01:37 PM #1
multiple cursor with date handling issue reg Dear all,
i am using three cursors in one pl/sql block each of this three cursor will fetch data based on column of date data type.i believe due to each condition relate to same table,contradiction may arise i.e
1> when code will execute , cursor c1 will do the job perfectly but c2 & c3 here may not be able to solve the purpose since the job has already been done by cursor c1 which i am not sure.my doubts i need all cursor to work based on each condition.
any suggestion from your side could sort out this issues.
Thanks n regards
Laxman
Code sql:declare
begin
FOR c1 IN(SELECT reqid FROM request WHERE lastmoddate<sysdate - 8/24 AND statuscode=1 AND assigned_personid IS NOT NULL)loop
UPDATE srequest SET STATUS=open WHERE reqid=c1.reqid;
commit;
end loop;
FOR c2 IN(SELECT reqid FROM request WHERE lastmoddate<sysdate - 1 AND statuscode=1 AND assigned_personid IS NULL)loop
UPDATE srequest SET STATUS=open WHERE reqid=c2.reqid;
commit;
end loop;
FOR c3 IN(SELECT reqid FROM request WHERE lastmoddate<sysdate - 14 AND statuscode=1 AND assigned_personid IS NULL)loop
UPDATE srequest SET STATUS=open WHERE reqid=c3.reqid;
commit;
end loop;
end;
- Club-Oracle Complementary E-Books and Magazines
Get your free Complementary Copy of Oracle Magazine
You can also browse the Free Magazines and E-Books section to see the complete list of free magazines, e-books and Whitepapers.
- 03-10-2010 07:34 PM #2
Re: multiple cursor with date handling issue reg The real problem with this code is the commits inside loops. Rewrite the code like this:
Code sql:begin
FOR c1 IN(SELECT reqid FROM request WHERE lastmoddate<sysdate - 8/24 AND statuscode=1 AND assigned_personid IS NOT NULL)loop
UPDATE srequest SET STATUS=open WHERE reqid=c1.reqid;
end loop;
commit;
FOR c2 IN(SELECT reqid FROM request WHERE lastmoddate<sysdate - 1 AND statuscode=1 AND assigned_personid IS NULL)loop
UPDATE srequest SET STATUS=open WHERE reqid=c2.reqid;
end loop;
commit;
FOR c3 IN(SELECT reqid FROM request WHERE lastmoddate<sysdate - 14 AND statuscode=1 AND assigned_personid IS NULL)loop
UPDATE srequest SET STATUS=open WHERE reqid=c3.reqid;
end loop;
commit;
end;
/
As for your concern that the cursors 'may not be able to solve the purpose' I wonder why you think such things. I suggest you run the queries in sequence and note that they do, indeed, 'solve the purpose'.
- 03-11-2010 03:24 AM #3
Re: multiple cursor with date handling issue reg Thanks sir for ur kind responce,yes i agree this will definitly work,what my intention was that all the three cursor are doing the same job based on different condition.if u can see c2 and c3 .
cursor c2---> lastmoddate< sysdate - 1
cursor c3 ---> lastmoddate< sysdate - 14
job of cursor c3 is already been done by c2 since sysdate - 14 < sysdate - 1,this may cause a replicate of data when c3 will start execute.what i need here is in order to avoid the replicate of data can i merge all the job into single cursor ??? will it work !!!
need ur suggestion kindly
Regards
Laxman
- 03-17-2010 05:54 AM #4
Re: multiple cursor with date handling issue reg It could be merged as
begin
Code sql:FOR c IN(SELECT reqid
FROM request
WHERE statuscode=1
AND (( assigned_personid IS NULL AND ( sysdate - 1 OR lastmoddate<sysdate - 14 ))
OR
( assigned_personid IS NOT NULL AND ( lastmoddate<sysdate - 8/24 )))
)
loop
UPDATE srequest SET STATUS='open' WHERE reqid=c.reqid;
end loop;
commit;
Or using straight SQL as follows
Code sql:UPDATE request
SET STATUS='Open'
WHERE statuscode=1
AND (( assigned_personid IS NULL AND ( sysdate - 1 OR lastmoddate<sysdate - 14 ))
OR
( assigned_personid IS NOT NULL AND ( lastmoddate<sysdate - 8/24 )));
Raj.
Similar Threads
-
cursor with exception issue reg
By laxman in forum SQL PL/SQLReplies: 6Last Post: 03-10-2010, 06:49 AM -
date manipultation issue reg
By laxman in forum SQL PL/SQLReplies: 2Last Post: 03-04-2010, 03:02 AM -
Oracle SQL Nested Cursor Issue
By laxman in forum SQL PL/SQLReplies: 3Last Post: 02-25-2010, 07:08 PM -
nested cursor loop issue reg.
By laxman in forum SQL PL/SQLReplies: 2Last Post: 02-24-2010, 08:12 AM


LinkBack URL
About LinkBacks
Reply With Quote





