Oracle PL/SQL 根据条件批量收集到一列集合中

发布于 2024-12-18 07:34:31 字数 515 浏览 6 评论 0原文

我在一个架构中有下表:User_Codes(useri_id, user_code)。我想从存储过程中的另一个模式访问此表,并最大限度地减少模式之间的往返次数。

在存储过程中,我有一个包含用户数据和用户 ID 的集合。我想使用 user_ids 从其他架构中获取相应的 user_codes。因此,假设 rowset 是一个集合或 SQL TABLE,其中包含已填充 user_ids 和待填充 user_codes 的用户数据,我想要的是这样的:

select uc.user_code
bulk collect into rowset.user_code
from other_schema.user_codes uc
where uc.user_id in (
 select distinct rowset_table.user_id
 from table(rowset) rowset_table
 where rowset_table.user_id is not null
);

这可能吗?

I have the following table in one schema: User_Codes(useri_id, user_code). I want to access this table from another schema in a stored proc and minimize the number of round trips between schemas.

In the stored proc I have a collection containing user data along with user ids. I want to fetch corresponding user_codes from other schema using the user_ids. So assuming that rowset is a collection or SQL TABLE containing user data with filled user_ids and to be filled user_codes, what I want is something like this:

select uc.user_code
bulk collect into rowset.user_code
from other_schema.user_codes uc
where uc.user_id in (
 select distinct rowset_table.user_id
 from table(rowset) rowset_table
 where rowset_table.user_id is not null
);

Is this possible?

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

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

发布评论

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

评论(1

深居我梦 2024-12-25 07:34:31

只是一个疯狂的猜测,但这也许对你有用:

select rs.user_id, uc.user_code
  bulk collect into rowset
  from other_schema.user_codes uc, table(rowset) rs
  where uc.user_id = rs.user_id;

Just a wild guess, but maybe this works for you:

select rs.user_id, uc.user_code
  bulk collect into rowset
  from other_schema.user_codes uc, table(rowset) rs
  where uc.user_id = rs.user_id;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文