我有一个将帐户分组在一起的关联表。
我正在尝试选择表'target‘的一个子集
p_group_id := 7;
select *
target t
where t.account_id in get_account_ids(p_group_id);是否可以编写一个返回account_ids列表(作为某种形式的集合)的函数来简化上面的代码?
我已经研究了流水线函数,但是我想远离循环和游标。另外,自定义类型/表也会影响到类型转换,这是我想要避免的。
作为参考,假设函数'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;发布于 2012-02-03 08:47:16
你只需要:
select *
from target t
where t.account_id in
( select aa.account_id
from assoc_account aa
where aa.groupid = 7;
)假设assoc_account.account_id永远不是NULL,上面的方法将会起作用。
https://stackoverflow.com/questions/9121648
复制相似问题