从 Oracle Cursor 批量收集列的子集

发布于 2024-10-03 20:13:27 字数 329 浏览 4 评论 0原文

给定的存储过程无法更改。它返回游标,结果中包含许多列。 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 INTOonly 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 技术交流群。

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

发布评论

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

评论(2

夜巴黎 2024-10-10 20:13:27

简短的答案是“不”,您将不得不做您说过不想做的事情之一,除非您可以更改存储过程,或者编写一个新的存储过程来执行您想要的操作。

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.

人生百味 2024-10-10 20:13:27

您无法立即处置不需要的列。

您可以为游标的每一列声明 PL/SQL 表,如下所示:

type c_col1 is table of s_cursor.col1%type index by pls_integer;
type c_col2 is table of s_cursor.col2%type index by pls_integer;
type c_col3 is table of s_cursor.col3%type index by pls_integer;
t_col1 c_col1;
t_col2 c_col2;
t_col3 c_col3;

并批量收集到这些表中:

fetch s_cursor bulk collect into t_col1, t_col2, t_col3;

并删除不需要的集合:

t_col2.delete;
t_col3.delete;

但是,这需要编写更多代码,并且比批量收集需要更多时间来执行收集光标处的所有列并假装不存在不需要的列。

You can't dispose of unwanted columns immediately.

You could declare PL/SQL tables for each column of the cursor like this:

type c_col1 is table of s_cursor.col1%type index by pls_integer;
type c_col2 is table of s_cursor.col2%type index by pls_integer;
type c_col3 is table of s_cursor.col3%type index by pls_integer;
t_col1 c_col1;
t_col2 c_col2;
t_col3 c_col3;

and bulk collect into these tables:

fetch s_cursor bulk collect into t_col1, t_col2, t_col3;

and delete the collections you don't need:

t_col2.delete;
t_col3.delete;

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.

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