I didn't see in the documentation that you can't use an aggregate inside an sql_macro(scalar)
.. or, at least, it's not stating it clearly. “A scalar macro cannot have table arguments.” – does this mean “No Aggregates”?
If I attempt to use an aggregate, I get:
ORA-00918: PRODUCT: column ambiguously specified - appears in and
create or replace
function product( P in number ) return varchar2
sql_macro(scalar)
as
begin
-- return '( EXP(SUM(LN( P ))) )'; -- fails
-- return '( sum(LN( P )) )'; -- fails
return '( LN( P ) )'; -- works
end;
/
select product( d.T ) as abc
from (
select 5 T union all
select 6
) d;