[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to rewind opened cursor in PL/SQL

Posted on 1997-12-10
1
Medium Priority
?
2,994 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 600 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
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 about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
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…
Suggested Courses

831 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