Team,
Is it not possible to have with clause "subquery" and function together? the following (was modelled like our application code) is from ATP 19c
with rws as (
select object_name r from all_objects
where rownum <= 10
union all
select username from all_users
where rownum <= 10
)
, function foo( p_str varchar2 )
return varchar2
as
begin
return ( replace(p_str,'!@#$%^&*()') ) ;
end;
select r, foo(r) from rws ;
but ended with errors like this
demo@PDB1> with rws as (
2 select object_name r from all_objects
3 where rownum <= 10
4 union all
5 select username from all_users
6 where rownum <= 10
7 )
8 , function foo( p_str varchar2 )
9 return varchar2
10 as
11 begin
12 return ( replace(p_str,'!@#$%^&*()') ) ;
, function foo( p_str varchar2 )
*
ERROR at line 8:
ORA-00905: missing keyword
demo@PDB1> end;
SP2-0042: unknown command "end" - rest of line ignored.
demo@PDB1> select r, foo(r)
2 from rws ;
from rws
*
ERROR at line 2:
ORA-00942: table or view does not exist
so we modified like this and it worked.
demo@PDB1> with function foo( p_str varchar2 )
2 return varchar2
3 as
4 begin
5 return ( replace(p_str,'!@#$%^&*()') ) ;
6 end;
7 select r, foo(r)
8 from (
9 select object_name r from all_objects
10 where rownum <= 10
11 union all
12 select username from all_users
13 where rownum <= 10
14 )
15 /
R FOO(R)
------------------------------ ------------------------------
I_FILE#_BLOCK# I_FILE#_BLOCK#
I_OBJ3 I_OBJ3
I_TS1 I_TS1
I_CON1 I_CON1
IND$ IND$
CDEF$ CDEF$
C_TS# C_TS#
I_CCOL2 I_CCOL2
I_PROXY_DATA$ I_PROXY_DATA$
I_CDEF4 I_CDEF4
SYS SYS
AUDSYS AUDSYS
SYSTEM SYSTEM
OUTLN OUTLN
GSMADMIN_INTERNAL GSMADMIN_INTERNAL
GSMUSER GSMUSER
DIP DIP
REMOTE_SCHEDULER_AGENT REMOTE_SCHEDULER_AGENT
DBSFWUSER DBSFWUSER
ORACLE_OCM ORACLE_OCM
20 rows selected.