Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keeping a cursor open 1

Status
Not open for further replies.

BJCooperIT

Programmer
May 30, 2002
1,210
US
I really could use a pair of fresh eyes to look at what should be a simple matter. I have a package that opens a cursor and should return data from one row at a time. However, in testing it does not recognize that the cursor is open on the second time in and reopens the cursor.
Code:
CREATE OR REPLACE PACKAGE BODY pkg_test IS

    PROCEDURE get_a_state 
    (
        p_name      IN OUT state_table.NAME%TYPE,
        p_return       OUT VARCHAR2 
    )
    IS
        CURSOR my_cursor IS
                SELECT  NAME
                FROM    state_table
                ORDER BY NAME;
    BEGIN
        p_return := 'OK';

        IF  NOT my_cursor%ISOPEN THEN   --If not open, then open
            OPEN my_cursor;
        END IF;
        
        FETCH my_cursor INTO p_name;    --Get next row

        IF my_cursor%NOTFOUND THEN      --See if at end of rows
            CLOSE my_cursor;
            p_return := 'EF';
        END IF;
    END get_a_state;
BEGIN
    NULL;
END pkg_test;
Code:
DECLARE
    v_name   VARCHAR2(100) := NULL;
    v_return VARCHAR2(100) := NULL;
BEGIN
    FOR i IN 1 .. 2
    LOOP
        pkg_test.get_a_state(v_name, v_return);
        upk.dopl(v_name || ' ' || v_return);
    END LOOP;
END;
Code:
Alabama OK
Alabama OK
What have I missed?

Beware of false knowledge; it is more dangerous than ignorance. ~George Bernard Shaw
Consultant Developer/Analyst Oracle, Forms, Reports & PL/SQL (Windows)
My website: www.EmuProductsPlus.com
 
Like a charm! Thanks Jim.

Beware of false knowledge; it is more dangerous than ignorance. ~George Bernard Shaw
Consultant Developer/Analyst Oracle, Forms, Reports & PL/SQL (Windows)
My website: www.EmuProductsPlus.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top