1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| SQL> create or replace context my_ctx using my_ctx_procedure
2 /
Context created.
SQL> create or replace procedure my_ctx_procedure ( p_str in varchar2 )
2 as
3 begin
4 dbms_session.set_context ( 'my_ctx', 'txt', p_str );
5 end;
6 /
Procedure created.
SQL> create or replace view IN_LIST
2 as
3 select trim( substr (txt,
4 instr (txt, ',', 1, level ) + 1,
5 instr (txt, ',', 1, level+1)
6 - instr (txt, ',', 1, level) -1 ) ) as token
7 from (select ','||sys_context('my_ctx','txt')||',' txt
8 from dual)
9 connect by level <= length(sys_context('my_ctx','txt'))
10 -length(replace(sys_context('my_ctx','txt'),',',''))+1
11 /
View created.
SQL> CREATE OR REPLACE procedure p (p_param IN number, c OUT sys_refcursor)
2 as
3 begin
4 if p_param = 3 then
5 my_ctx_procedure( '1,2' );
6 elsif p_param = 1 then
7 my_ctx_procedure( '3' );
8 else
9 my_ctx_procedure( '1,2,3' );
10 end if;
11 open c for select * from t where col in (select * from IN_LIST);
12 end;
13 /
Procedure created.
SQL> show err
No errors.
SQL> var rc refcursor
SQL> execute p (3,:rc)
PL/SQL procedure successfully completed.
SQL> print rc
COL
----------
1
2
SQL> execute p (1,:rc)
PL/SQL procedure successfully completed.
SQL> print rc
COL
----------
3
SQL> execute p (8,:rc)
PL/SQL procedure successfully completed.
SQL> print rc
COL
----------
1
2
3 |
Partager