Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: Which is beter a cursor or a for loop?

RE: Which is beter a cursor or a for loop?

From: Lord, David - CSG <david.lord_at_hays.com>
Date: Mon, 24 Feb 2003 03:13:43 -0800
Message-ID: <F001.0055666C.20030224031343@fatcity.com>


This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible.

------_=_NextPart_001_01C2DBF5.0AC6B3E0
Content-Type: text/plain; charset="iso-8859-1"

Denham  

The for loop is a lot easier to read. It can be a real pain scrolling to the top every time you want to see what such-and-such a cursor is doing. On the other hand, it can be a bit limiting in more 'advanced' situations - eg. you can't mess around with cursor%rowtype variables and you can't fetch from the cursor in more than one place.  

Regards
David Lord

-----Original Message-----
Sent: 24 February 2003 08:39
To: Multiple recipients of list ORACLE-L

Hello,

I was just asked by one of our developers which is beter to use:- a cursor or a for loop?
I must admit I am not sure....

Anyway the specific piece of code in discussion is similar to the following....    

        FOR X IN (SELECT X FROM TABLE_NAME 
                    WHERE COL1 = 'Something')) 
            LOOP 
                Do a whole lot of stuff in database here...... 
            LOOP END; 

I would guess that the cursor would follow similar execution criteria but using
the cursor syntax.

Any ideas?

TIA
regards
Denham Eva
Oracle DBA
The real problem is not whether machines think but whether men do. - B. F. Skinner


DISCLAIMER This message is for the named person's use only. It may contain confidential, proprietary or legally privileged information. No confidentiality or privilege is waived or lost by any mistransmission. If you receive this message in error, please immediately delete it and all copies of it from your system, destroy any hard copies of it and notify the sender. You must not, directly or indirectly, use, disclose, distribute, print, or copy any part of this message if you are not the intended recipient. TFMC, its holding company, and any of its subsidiaries each reserve the right to monitor and manage all e-mail communications through its networks.

Any views expressed in this message are those of the individual sender, except where the message states otherwise and the sender is authorized to state them to be views of any such entity.



This e-mail message has been scanned for Viruses and Content and cleared by MailMarshal - For more information please visit
<http://www.marshalsoftware.com> www.marshalsoftware.com




This message (including any attachments) is confidential and may be legally privileged. If you are not the intended recipient, you should not disclose, copy or use any part of it - please delete all copies immediately and notify the Hays Group Email Helpdesk at email.helpdesk_at_hays.com
Any information, statements or opinions contained in this message (including any attachments) are given by the author. They are not given on behalf of Hays unless subsequently confirmed by an individual other than the author who is duly authorised to represent Hays.  

A member of the Hays plc group of companies. Hays plc is registered in England and Wales number 2150950. Registered Office Hays House Millmead Guildford Surrey GU2 4HJ.


------_=_NextPart_001_01C2DBF5.0AC6B3E0
Content-Type: text/html; charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>Which is beter a cursor or a for loop?</TITLE>

<META content="MSHTML 6.00.2716.2200" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=741430311-24022003><FONT face="Courier New"
size=2>Denham</FONT></SPAN></DIV>
<DIV><SPAN class=741430311-24022003><FONT face="Courier New"
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=741430311-24022003><FONT face="Courier New" size=2>The for loop
is a lot easier to read.&nbsp; It can be a real pain scrolling to the top every time you want to see what such-and-such a cursor is doing.&nbsp; On the other hand, it can be a bit limiting in more 'advanced' situations - eg. you can't mess around with cursor%rowtype variables and you can't fetch from the cursor in more than one place.</FONT></SPAN></DIV>
<DIV><SPAN class=741430311-24022003><FONT face="Courier New"
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=741430311-24022003><FONT face="Courier New"
size=2>Regards</FONT></SPAN></DIV>
<DIV><SPAN class=741430311-24022003><FONT face="Courier New" size=2>David
Lord</FONT></SPAN></DIV>
<BLOCKQUOTE

style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid">   <DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma

  size=2>-----Original Message-----<BR><B>From:</B> Denham Eva 
  [mailto:EvaD_at_TFMC.co.za]<BR><B>Sent:</B> 24 February 2003 08:39<BR><B>To:</B> 
  Multiple recipients of list ORACLE-L<BR><B>Subject:</B> Which is beter a 
  cursor or a for loop?<BR><BR></FONT></DIV>   <P><FONT face=Arial size=2>Hello,</FONT> </P>   <P><FONT face=Arial size=2>I was just asked by one of our developers which is   beter to use:-</FONT> <BR><FONT face=Arial size=2>a cursor or a for   loop?</FONT> <BR><FONT face=Arial size=2>I must admit I am not sure....</FONT>   </P>
  <P><FONT face=Arial size=2>Anyway the specific piece of code in discussion is   similar to the following....</FONT> <BR><FONT face=Arial size=2>&nbsp;&nbsp;   </FONT><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT face=Arial   size=2>FOR X IN (SELECT X FROM TABLE_NAME</FONT>   <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT face=Arial
  size=2>&nbsp;&nbsp;&nbsp; WHERE COL1 = 'Something'))</FONT> <BR><FONT 
  face=Arial 
  size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  LOOP</FONT> <BR><FONT face=Arial
  size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   Do a whole lot of stuff in database here......</FONT> <BR><FONT face=Arial   size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LOOP   END;</FONT> </P>
  <P><FONT face=Arial size=2>I would guess that the cursor would follow similar   execution criteria but using </FONT><BR><FONT face=Arial size=2>the cursor   syntax.</FONT> </P>
  <P><FONT face=Arial size=2>Any ideas?</FONT> </P>   <P><FONT face=Arial size=2>TIA</FONT> <BR><FONT face=Arial   size=2>regards<B><I></I></B></FONT><B><I></I></B> <BR><B><I><FONT   face=Arial>Denham Eva</FONT></I></B> <BR><B><I><FONT face=Arial size=2>Oracle   DBA</FONT></I></B> <BR><I><FONT face=Arial size=2>The real problem is not   whether machines think but whether men do.</FONT></I> <BR><I><FONT face=Arial   size=2>- B. F. Skinner</FONT></I> </P><STRONG><FONT face=Arial color=#0000a0>
  <P>
  <HR>
  </FONT></STRONG><STRONG><FONT face=Arial color=#0000a0 
  size=2>DISCLAIMER</FONT> </STRONG>
  <P></P>
  <P><FONT size=1><FONT face=Arial>This message is for the named person's use   only. It may contain confidential, proprietary or legally privileged   information. No confidentiality or privilege is waived or lost by any   mistransmission. If you receive this message in error, please immediately   delete it and all copies of it from your system, destroy any hard copies of it   and notify the sender. You must not, directly or indirectly, use, disclose,   distribute, print, or copy any part of this message if you are not the   intended recipient. TFMC, its holding company, and any of its subsidiaries   each reserve the right to monitor and manage all e-mail communications through   its networks.</FONT> </FONT></P>
  <P><FONT size=1><FONT face=Arial>Any views expressed in this message are those   of the individual sender, except where the message states otherwise and the   sender is authorized to state them to be views of any such entity.</FONT>   </FONT>
  <HR>

  <P></P>
  <HR>
  This e-mail message has been scanned for Viruses and Content and cleared by   <STRONG><FONT color=#ff8000>MailMarshal</FONT> - </STRONG>For more information   please visit<STRONG> </STRONG><A
  href="http://www.marshalsoftware.com"><STRONG>www.marshalsoftware.com</STRONG></A><STRONG>   </STRONG>
  <HR>
</BLOCKQUOTE><CODE><FONT SIZE=3><BR>
<BR>

**********************************************************************<BR>
This message (including any attachments) is confidential and may be <BR> legally privileged. If you are not the intended recipient, you should <BR> not disclose, copy or use any part of it - please delete all copies <BR> immediately and notify the Hays Group Email Helpdesk at<BR> email.helpdesk_at_hays.com<BR>
Any information, statements or opinions contained in this message<BR> (including any attachments) are given by the author. They are not <BR> given on behalf of Hays unless subsequently confirmed by an individual<BR> other than the author who is duly authorised to represent Hays.<BR>  <BR>
A member of the Hays plc group of companies.<BR> Hays plc is registered in England and Wales number 2150950.<BR> Registered Office Hays House Millmead Guildford Surrey GU2 4HJ.<BR>
**********************************************************************<BR>

</FONT></CODE>
</BODY></HTML>

------_=_NextPart_001_01C2DBF5.0AC6B3E0--

-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.net
-- 
Author: Lord, David - CSG
  INET: david.lord_at_hays.com

Fat City Network Services    -- 858-538-5051 http://www.fatcity.com
San Diego, California        -- Mailing list and web hosting services
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
Received on Mon Feb 24 2003 - 05:13:43 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US