功能性Where-in子句 - Oracle PL/SQL

Jam*_*ama 1 oracle associations where-clause

我有一个将帐户分组在一起的关联表.

我正在尝试选择表'target'的子集

p_group_id := 7;

select *
target t
where  t.account_id in get_account_ids(p_group_id);
Run Code Online (Sandbox Code Playgroud)

是否有可能编写一个函数来返回一个account_id列表(作为某种形式的集合),以便于上述代码?

我看过流水线函数,但是我想远离循环和游标.此外,自定义类型/表也进入我想避免的转换.

作为参考,假设函数'get_account_ids'会做什么,这里有一些伪代码:

function get_account_ids(p_group_id) 
  insert into v_ret
  select aa.account_id
  from   assoc_account aa
  where  aa.groupid = p_group_id;

return v_ret;
Run Code Online (Sandbox Code Playgroud)

ype*_*eᵀᴹ 5

你只需要:

select *
from   target t
where  t.account_id in 
       ( select aa.account_id
         from   assoc_account aa
         where  aa.groupid = 7;
       )
Run Code Online (Sandbox Code Playgroud)

以上将是有效的,假设assoc_account.account_id永远不会NULL.