2012-02-02 12 views
1

アカウントをまとめてグループ化する関連付けテーブルがあります。機能場所句 - Oracle PL/SQL

私は上記のコードを容易にテーブル「ターゲット」

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; 

答えて

5

あなたが単に必要があります。

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