如何在执行期间填充游标
我目前正在尝试在过程中填充光标。
就像这样:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您要求的是“我可以根据在声明游标时不必定义的查询创建游标吗”
如果这就是您想要的,请在此处查找有关动态 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
我不太确定你要做什么 - 填充光标?游标基于查询,那么您打算如何填充它呢?也许您想根据游标填充表格?您可以通过将游标结果累积到一个集合中,然后使用批量插入来填充表来做到这一点。
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.