V
V
vayho2013-11-08 13:52:10
Oracle
vayho, 2013-11-08 13:52:10

Does the cursor in a for loop statement in Oracle close when the function exits?

The official documentation does not describe what happens to the cursor if called RETURNinside CURSOR FOR LOOP STATEMENT. Perhaps I misunderstood something, so I'm asking here if the cursor closes or not?
Maybe someone met with a similar situation in the process of work and knows for sure, or can tell where to dig?
Approximate description of the function:

FUNCTION FUNC_NAME RETURN  VARCHAR2
AS
    CURSOR cursor_name IS SELECT DISTINCT field_name FROM table_name;               
BEGIN
    FOR row IN cursor_name LOOP
        RETURN NULL; -- Закроется ли курсор после выполнения этой строки?
    END LOOP;
    RETURN NULL;
END FUNC_NAME;

The code is not working, it is written in order to make it clear what the question is about.
Link to off documentation docs.oracle.com/cd/E11882_01/appdev.112/e17126/cur... .

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir_Izotov, 2013-11-09
@Vladimir_Izotov

During an exception, the cursor closes automatically. I think that during the return too.
A quick search turned up this:
Oracle PL/SQL For Dummies. Authors: Michael Rosenblum,Paul Dorsey
page 152
Found at this link.

M
Maxim, 2013-11-09
@mgramin

Here are some interesting comments and some useful links - www.sql.ru/forum/1027878/chto-esli-ne-zakryvat-kursor-v-pl-sql?hl=%e7%e0%ea%f0%fb%f2% e8%e5%20%ea%f3%f0%f1%ee%f0%e0

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question