Solved

How to rewind opened cursor in PL/SQL

Posted on 1997-12-10
1
2,837 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
1 Comment
 

Accepted Solution

by:
leonidt earned 150 total points
Comment Utility
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now