Prepare for your Next Interview
This is a discussion on doubt in sql within the Oracle forums, part of the Databases category; what are the disadvantages of cursors.pls give one example for each disadvantage...
|
|||
|
Re: doubt in sql
I think there are no disadvantages with triggers; it is completely depended on our need and usage, mostly the problem occurs when we are not handling them properly i will give u an example so you can understand that,
create trigger trg1 before insert on emp for each row begin if :new.hiredate > sysdate then raise_application_error(-20001,'hire date cannot be in the future'); end if; end; in the above trigger we are handling the hire date colum, whenever we affect hire date colum it will check with triggering event if it is “true” it will fire the trigger. So here no issues now have a look in to this i’m giving you one more trigger which belongs to same entity and handling the same hire date colum, let us check with it create trigger trg2 before insert on emp for each row begin if :new.hiredate is null then :new.hiredate := sysdate+1; end if; end; / here we gave both triggers to the same entity and to the same colum, carefully observe the triggers, both are completely opposite. What happens if we are having this both triggers together? if trg2 fires before trg1 then: 1) hire date gets set to tomorrow's date 2) record is rejected because 'hire date cannot be in the future' if trg1 fires before trg2 then: 1) record is not rejected, because null hire date isn't in the future 2) hire date gets set to tomorrow's date imp note: why we are facing the problem is, we can’t guarantee that which trigger will be fired first. In our case if trg1 fires before trg2 it will go fine, but if it was reverse we have to face severe problem. This is all due to wrong handling the triggers,we have to design the triggers very carefully. In this case we can solve the problem easily we can modify the trg1 as after update or insert. So then trg2 will be fired first than trg1. Thank you for asking such a beautiful questions and one more thing, really i don’t know whether we are having any disadvantages in triggers, i heard that few people are facing problems while dealing with calculations by using triggers. If you find anything please reply me, bye sudheer |
| The Following User Says Thank You to su123 For This Useful Post: | ||
|
|||
|
Re: doubt in sql
Each time you fetch a row from the cursor, it results in a network roundtrip; where as a normal SELECT query makes only one roundtrip, however large the result set is. Cursors are also costly because they require more resources and temporary storage. Further, there are restrictions on the SELECT statements that can be used with some types of cursors.
So better to use the cursor when you are trying to fetch less than 3% of records from the entites. Most of the times, set based operations can be used instead of cursors. I don't know the list of disadvantages in cursors, This is the information I know about that. byee |
| The Following User Says Thank You to su123 For This Useful Post: | ||
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| a doubt.... | Ammu_R | PHP | 1 | 08-17-2007 10:51 AM |
| doubt | Santhana KrishnaN | C# | 3 | 06-07-2007 11:42 PM |
| doubt in qtp | thejovathich | QTP | 2 | 04-30-2007 08:02 AM |
| doubt reg bug in SRS and FRS | venkatsagehill | Testing Issues | 3 | 02-19-2007 07:59 AM |