Please consider the following script:
create or replace function f(p_limit in integer) return integer as
begin
set_global_context ('limit', p_limit);
return p_limit;
end;
/
create view v as
select level as val from dual connect by level<=sys_context('global_context','limit');
select f(2), v.* from v;
/*
F(2) VAL
---------------------- ----------------------
2 1
2 2
*/
select f(4), v.* from v;
/*
F(4) VAL
---------------------- ----------------------
4 1
4 2
4 3
4 4
*/
Can I rely on f(x)
being executed before the context is read inside the view, as it has been in this test case run on 10.2?
SELECT stuff FROM dbo.FuncReturningTable(param)
or similar. Oracle probably has equivalent functionality. Though if using this over large data sets I'd be careful to monitor performance: I'm not sure how bright the query planner would need to be to make an efficient plan from such syntax.