Solved

How to rewind opened cursor in PL/SQL

Posted on 1997-12-10
1
2,897 Views
Last Modified: 2008-02-01
Hi!

I'm writing procedure in PL/SQL for ORACLE 8.
I need to run the same SQL statment in a loop, in witch I reopen the
cursor everytime I get to the head of loop. The cursor parameters
doesn't change.

Is it possible to rewind opened cursor to save the time and don't
open the cursor for reading the database each time getting the head
of the loop after closing this cursor at the loop bottom ?

thanks.

    Alex Ziablitsev
0
Comment
Question by:alz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
leonidt earned 150 total points
ID: 1081117
Unforunately OPEN statement for cursor corresponds to the
PARSE, BIND and EXECUTE operations.
In your case you basically don't need to do PARSE and BIND
you just need to reexecute SQL stmt (probably because your
data in a table(s) have changed. If you really want to do it
everything in PL/SQL then  
my only suggestion is to use DBMS_SQL package which gives you
more flexibility. You put
DBMS_SQL.OPEN_CURSOR, DBMS_SQL.PARSE AND DBMS_SQL.DEFINE_COLUMN
outside the loop. If you bind any variable (or if in your
original program you had the parameterised cursor and the parameter changed in the loop) you put the
DBMS_SQL.BIND_VARIABLE inside the loop. You do
DBSM_SQL.EXECUTE inside the loop and then fetch the rows
from your cursor.

Basically the same schema is used when you are using
C/C++ or Visual Basic from the client.

You don't need to Open and Close the Cursor any more inside the loop.

From my experience there is very small overhead in comparison with the cursors.




0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question