使用/在另一个游标中调用游标 - PL / Sql

时间:2011-11-14 16:23:22

标签: function plsql database-cursor

我有一个带有游标的函数,它返回一个ID。我需要使用第一个游标的ID结果在另一个游标中获取一些字段。

所以我的第一个光标是:

CREATE OR REPLACE function get_id(id number) 

CURSOR child_id
   IS
       SELECT table1_id
            FROM table1,child
              WHERE child_id = id
          AND table1_id = child_chld_id;

理想情况下,我的第二个光标应该是:

cursor grandchild_id
is
select table1_id from table1,child
where child_id = (return value of id from cursor child_id)
and table1_id = child_chld_id; 

我该怎么做?

1 个答案:

答案 0 :(得分:1)

游标可以接受参数:

cursor grandchild_id(other_child_id number)
is
select table1_id from table1,child
where child_id = grandchild_id.other_child_id
and table1_id = child_chld_id; 

无论何时打开grandchild_id游标,只需将相应的值作为参数传递:

grandchild_id(the_value_you_obtained_from_the_first_cursor)
相关问题