Geeks Talk

Prepare for your Next Interview




doubt in sql

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...


Go Back   Geeks Talk > Databases > Oracle

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 03-03-2008
Banned
 
Join Date: Feb 2008
Location: bangalore
Posts: 32
Thanks: 9
Thanked 2 Times in 2 Posts
jayanth511 is on a distinguished road
doubt in sql

what are the disadvantages of cursors.pls give one example for each disadvantage
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-03-2008
Moderator
 
Join Date: Jun 2007
Location: Bangalore,India
Posts: 1,432
Thanks: 8
Thanked 126 Times in 113 Posts
debasisdas will become famous soon enoughdebasisdas will become famous soon enough
Re: doubt in sql

Your question is too much theoretical and is beyond the scope of this discussion. Please invest some quality time in web searching for all that.
Reply With Quote
  #3 (permalink)  
Old 03-03-2008
Junior Member
 
Join Date: Feb 2008
Location: Edinburgh
Posts: 21
Thanks: 3
Thanked 2 Times in 2 Posts
su123 is on a distinguished road
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
Reply With Quote
The Following User Says Thank You to su123 For This Useful Post:
  #4 (permalink)  
Old 03-03-2008
Banned
 
Join Date: Feb 2008
Location: bangalore
Posts: 32
Thanks: 9
Thanked 2 Times in 2 Posts
jayanth511 is on a distinguished road
Re: doubt in sql

sorry iam asking about cursors disadvantages.any way u sent lot of informationthanksssss
Reply With Quote
  #5 (permalink)  
Old 03-03-2008
Junior Member
 
Join Date: Feb 2008
Location: Edinburgh
Posts: 21
Thanks: 3
Thanked 2 Times in 2 Posts
su123 is on a distinguished road
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
Reply With Quote
The Following User Says Thank You to su123 For This Useful Post:
Reply

  Geeks Talk > Databases > Oracle


Thread Tools
Display Modes


Similar Threads

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


All times are GMT -4. The time now is 08:49 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved