如何在执行期间填充游标

发布于 2024-08-12 17:45:25 字数 569 浏览 4 评论 0原文

我目前正在尝试在过程中填充光标。

就像这样:

Function notImportantFunction
   variable nothing(20);
   Cursor notImportantCursor Is select...;
   Cursor THEcursor;
begin
    open notImportantCursor;
    open THEcursor;
    LOOP
        FETCH notImportantCursor variable;
    EXIT WHEN notImportantCursor%NOTFOUND;
        THEcursor is select ...; //trying to populate THEcursor
    end loop;
    close THEcursor;
    close notImportantCursor;
end;

我为我的变量使用了奇怪的名称,只是为了显示这里唯一重要的一个是THEcursor。

我正在尝试的可能吗?或者,我怎样才能以另一种方式做同样的事情。

先感谢您

I am currently trying to populate a cursor in the procedure.

like that :

Function notImportantFunction
   variable nothing(20);
   Cursor notImportantCursor Is select...;
   Cursor THEcursor;
begin
    open notImportantCursor;
    open THEcursor;
    LOOP
        FETCH notImportantCursor variable;
    EXIT WHEN notImportantCursor%NOTFOUND;
        THEcursor is select ...; //trying to populate THEcursor
    end loop;
    close THEcursor;
    close notImportantCursor;
end;

i've used weird name for my variable just to show the only important one here is THEcursor.

is what i'm trying even possible? or, how would I be able to do the same in another way.

thank you in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

回心转意 2024-08-19 17:45:25

我认为您要求的是“我可以根据在声明游标时不必定义的查询创建游标吗”
如果这就是您想要的,请在此处查找有关动态 sql 的信息。

动态 SQL

有一个完美的例子引用编译时不存在的数据库对象部分。
您可以根据需要每次重新创建光标。
如果您需要更灵活的东西,例如创建一个在每个记录中保存三个值的游标,并且您想以不同的方式填充这些值,您可以寻找管道表函数

I think what you are asking for is "Can I create a cursor based on a query that I don't have to define when I declare the cursor"
If thats what you want, then look here for information about dynamic sql.

Dynamic SQL

There is a perfect example in the section Referencing Database Objects that Do Not Exist at Compilation.
You can recreate the cursor each time, however you want.
If you need something a little more flexible, like creating a cursor that holds three values in each record and you want to populate those values in different ways, you could look for pipelined table functions

明天过后 2024-08-19 17:45:25

我不太确定你要做什么 - 填充光标?游标基于查询,那么您打算如何填充它呢?也许您想根据游标填充表格?您可以通过将游标结果累积到一个集合中,然后使用批量插入来填充表来做到这一点。

I'm not quite sure what you're trying to do - populate a cursor? A cursor is based on a query, so how do you plan to populate that? Maybe you want to populate a table based on a cursor? You can do that by accumulating the cursor results into a collection then using a bulk-insert to populate the table.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文