RE: Quick (hopefully) pl/sql cursor question

  • From: "Sweetser, Joe" <JSweetser@xxxxxxxx>
  • To: Jacek Gębal <jgebal@xxxxxxxxx>
  • Date: Fri, 27 Sep 2019 18:52:42 +0000

Thanks!

To be clear, procedure3a has 2 cursor ‘definitions’ in the declaration section. 
 My tabs didn’t work for spacing last time.  I apologize if that happens again.

Procedure 3a is

Cursor c1 is select ….
Cursor c2 is select….

Begin
   For x in c1 loop
      Declare
           -set some constants
      Begin
           For y in c2 loop
           Do some stuff
       End loop;
   End loop;
End;

Would c2 still be initialized at the start of the ‘For y’ loop??  I think so 
but want to confirm.

Thanks again,
-joe

From: Jacek Gębal <jgebal@xxxxxxxxx>
Sent: Friday, September 27, 2019 12:32 PM
To: Sweetser, Joe <JSweetser@xxxxxxxx>
Cc: oracle-l <oracle-l@xxxxxxxxxxxxx>
Subject: Re: Quick (hopefully) pl/sql cursor question

If the cursor is implicit in procedure3a like:

FOR x IN (SELECT * FROM DUAL) LOOP
  --do some stuff here
  NULL;
END LOOP;

The cursor is initialized when the PLSQL engine goes into FOR ...LOOP statement.

Cheers,
Jacek

On Fri, 27 Sep 2019 at 18:27, Sweetser, Joe 
<JSweetser@xxxxxxxx<mailto:JSweetser@xxxxxxxx>> wrote:
Greetings,

Does anyone know exactly when an explicit cursor is initialized in pl/sql?  I 
understand I may need to supply more info, but I am no pl/sql wizard and don't 
know exactly what info is needed.

I have a package with multiple procedures.  One those procedures contains 
additional procedures.  And one of those additional procedures has some 
cursors.  Sorta like this:

Package
- procedure1
- procedure2
- procedure3
- procedure3a
- cursor 1
- cursor 2

Would the cursors be initialized when procedure3 is called or when procedure3a 
is called?  I would guess procedure3a but the developer is seeing some 
weirdness where it looks like it's when procedure3 is called.

There is no explicit "open cursor" call.  It is used in a for loop, so I think 
oracle opens it automagically.  But, again, I am trying to determine the 
initialization.  When is the cursor loaded with data?

Any/all ideas/suggestions welcome.

Thanks,
-joe

This e-mail transmission and any attachments that accompany it may contain 
information that is privileged, confidential or otherwise exempt from 
disclosure under applicable law and is intended solely for the use of the 
individual's to whom it was intended to be addressed. If you have received this 
e-mail by mistake, or you are not the intended recipient, any disclosure, 
dissemination, distribution, copying or other use or retention of this 
communication or its substance is prohibited. If you have received this 
communication in error, please immediately reply to the author via e-mail that 
you received this message by mistake and also permanently delete the original 
and all copies of this e-mail and any attachments from your computer. Please 
note that coverage cannot be bound or altered by sending an email. You must 
receive written confirmation from a representative of our firm to put coverage 
in force or make changes to an existing policy.
--
//www.freelists.org/webpage/oracle-l<https://nam05.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.freelists.org%2Fwebpage%2Foracle-l&data=02%7C01%7CJSweetser%40icat.com%7Ca9daa451d7ba471ed7c908d74378fa5a%7C5d3bf30e9adb4c17b2425c17523e6e5e%7C0%7C0%7C637052059196794770&sdata=X7GUSBTbN3s%2FwgxeVBs54k2KErca0BCO9G3KweMZeL4%3D&reserved=0>

This e-mail transmission and any attachments that accompany it may contain 
information that is privileged, confidential or otherwise exempt from 
disclosure under applicable law and is intended solely for the use of the 
individual's to whom it was intended to be addressed. If you have received this 
e-mail by mistake, or you are not the intended recipient, any disclosure, 
dissemination, distribution, copying or other use or retention of this 
communication or its substance is prohibited. If you have received this 
communication in error, please immediately reply to the author via e-mail that 
you received this message by mistake and also permanently delete the original 
and all copies of this e-mail and any attachments from your computer. Please 
note that coverage cannot be bound or altered by sending an email. You must 
receive written confirmation from a representative of our firm to put coverage 
in force or make changes to an existing policy.

Other related posts: