从 Oracle Cursor 批量收集列的子集
给定的存储过程无法更改。它返回游标,结果中包含许多列。 Oracle中有没有一种简单的方法可以BULK COLLECT INTO
仅由游标提供的列的子集?
应避免 FOR
循环和新的集合类型。我不想从游标中获取所有数据,只获取需要的数据。
例如,对于 BULK COLLECTION INTO
光标中的所有列,以下内容将起作用:
FETCH s_cursor BULK COLLECT INTO staff_ids;
A stored procedure is given that can't be changed. It returns a cursor with a number of columns in the result. Is there a simple way in Oracle to BULK COLLECT INTO
only a subset of columns provided by the cursor?
FOR
loops and new collection types should be avoided. I would not like to fetch all data from the cursor, just the data that is needed.
For example to BULK COLLECTION INTO
all columns from the cursor the following would work:
FETCH s_cursor BULK COLLECT INTO staff_ids;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简短的答案是“不”,您将不得不做您说过不想做的事情之一,除非您可以更改存储过程,或者编写一个新的存储过程来执行您想要的操作。
The short answer is "no", you will have to do one of the things you have said you don't want to do unless you can get the stored procedure changed, or get a new stored procedure written that does what you want.
您无法立即处置不需要的列。
您可以为游标的每一列声明 PL/SQL 表,如下所示:
并批量收集到这些表中:
并删除不需要的集合:
但是,这需要编写更多代码,并且比批量收集需要更多时间来执行收集光标处的所有列并假装不存在不需要的列。
You can't dispose of unwanted columns immediately.
You could declare PL/SQL tables for each column of the cursor like this:
and bulk collect into these tables:
and delete the collections you don't need:
However, this is more code to write and takes more time to execute than just bulk collecting all columns from the cursor and pretending that the unwanted columns aren't there.