1

How can I assign a function result to a name in the WITH clause?

Tried:

with
    has_perm as ( has_perm(:user) )
select * from my_table where has_perm = 'Y'
user5507535
  • 1,580
  • 1
  • 18
  • 39
  • I'm not sure what you mean by "assign a function result to a name in the WITH clause". Do you mean define an inline function, e.g. `with function has_perm(params) return number`, like [this](https://oracle-base.com/articles/12c/with-clause-enhancements-12cr1)? – William Robertson Apr 02 '21 at 17:41

1 Answers1

2

Is this what you want?

with has_perm as (
      select has_perm(:user) as has_perm
      from dual
     )
select *
from my_table
where 'Y' = (select has_perm from has_perm);

Why not just write this without a CTE?

select *
from my_table
where has_perm(:user) = 'Y';
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • Yes, that's what I want, though that there would be a better syntax to do this. Answering your question, because `has_perm` has many parameters in my case. – user5507535 Apr 02 '21 at 18:03