Solved

How to rewind opened cursor in PL/SQL

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

896 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

11 Experts available now in Live!

Get 1:1 Help Now