Open twice (or more) the same cursor

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bernard Drolet

    #1

    Open twice (or more) the same cursor

    Hi, I have a recursive table "Objectnew" with the columns "objectref"
    (primary key), objectname, objectid, and parentobjectid
    Recursive Relation: objectid ----< Parentobjectid

    I have the following cursor that extracts information about all
    objects with a specific name below a starting point

    DECLARE
    CURSOR findChildren(
    starting Objectnew.objec tref%TYPE,
    name Objectnew.objec tname%TYPE) IS
    SELECT
    objectref,
    objectname
    FROM
    Objectnew
    WHERE
    objectref in (
    SELECT
    objectref
    FROM
    Objectnew
    CONNECT BY PRIOR objectid = parentobjectid
    START WITH objectref = startingref
    ) AND
    objectname = name;

    What I need is, once I found some objects with a specific name, to run
    another query below each of them to find objects with another name.

    Something like
    OPEN findChildren(12 34, 'A');
    LOOP
    FETCH findChildren INTO ref, name
    EXIT WHEN findChildren%NO TFOUND;

    -- I have found an object A,
    -- I need to know if there is a B below A
    OPEN findChildren(re f, 'B');
    LOOP
    FETCH findChildren INTO ref2, name2
    EXIT WHEN findChildren%NO TFOUND;

    -- YES, there is a B, process it
    ....


    Is it possible without creating a duplicate of cursor findChildren ?


    Thank you


    Bernard Drolet
  • mcstock

    #2
    Re: Open twice (or more) the same cursor

    the cursor can only be opened once, but you could do a recursive procedure
    call, ie.:

    declare
    procedure findC (...
    cursor cFindC ...
    is
    ...
    -- found record, recursive call
    findC(...);
    ...
    end;
    begin
    -- initial call
    findC(...);
    end;

    (or create the recursively called procedure as a stored procedure)


    --
    Mark C. Stock
    email mcstock -enquery(dot)com

    (888) 512-2048

    "Bernard Drolet" <bernard@drolet .comwrote in message
    news:a9ccc9f9.0 311022000.2ce6a f4e@posting.goo gle.com...
    Hi, I have a recursive table "Objectnew" with the columns "objectref"
    (primary key), objectname, objectid, and parentobjectid
    Recursive Relation: objectid ----< Parentobjectid
    >
    I have the following cursor that extracts information about all
    objects with a specific name below a starting point
    >
    DECLARE
    CURSOR findChildren(
    starting Objectnew.objec tref%TYPE,
    name Objectnew.objec tname%TYPE) IS
    SELECT
    objectref,
    objectname
    FROM
    Objectnew
    WHERE
    objectref in (
    SELECT
    objectref
    FROM
    Objectnew
    CONNECT BY PRIOR objectid = parentobjectid
    START WITH objectref = startingref
    ) AND
    objectname = name;
    >
    What I need is, once I found some objects with a specific name, to run
    another query below each of them to find objects with another name.
    >
    Something like
    OPEN findChildren(12 34, 'A');
    LOOP
    FETCH findChildren INTO ref, name
    EXIT WHEN findChildren%NO TFOUND;
    >
    -- I have found an object A,
    -- I need to know if there is a B below A
    OPEN findChildren(re f, 'B');
    LOOP
    FETCH findChildren INTO ref2, name2
    EXIT WHEN findChildren%NO TFOUND;
    >
    -- YES, there is a B, process it
    ...
    >
    >
    Is it possible without creating a duplicate of cursor findChildren ?
    >
    >
    Thank you
    >
    >
    Bernard Drolet

    Comment

    Working...