【问题标题】:Using/Calling a cursor in another cursor - PL/Sql在另一个游标中使用/调用游标 - PL/Sql
【发布时间】:2011-11-14 16:23:21
【问题描述】:

我有一个带有返回 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; 

我该怎么做?

【问题讨论】:

  • @Anne - 感谢您的编辑。我永远不知道该怎么做!
  • 基本:粘贴代码,选择代码,点击{}按钮,确保上面的行是空的。希望有帮助!
  • 为什么不将它们合并到一个查询中呢?它很可能会更有效率。

标签: function plsql database-cursor


【解决方案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)

【讨论】:

  • 我将在 Oracle 发现者中使用它,它将为数据库中的所有 id 运行......在这种情况下它将如何工作?感谢您的回答
  • @Cindy:我不知道。您可能需要编辑您的问题以包含您正在使用 Discoverer 的事实。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多