I am trying to use a function declared in WITH clause, into a MERGE statement. Here is my code:
create table test
(c1 varchar2(10),
c2 varchar2(10),
c3 varchar2(10));
insert into test(c1, c2) values ('a', 'A');
insert into test(c1, c2) values ('b', 'A');
select * from test;
begin
with function to_upper(val varchar2) return varchar is
begin
return upper(val);
end;
merge into test a
using (select * from test) b
on (upper(a.c1) = upper(b.c2))
when matched then
update set a.c3 = to_upper(a.c1);
end;
but I am getting this error:
Error report - ORA-06550: line 2, column 15: PL/SQL: ORA-00905: missing keyword ORA-06550: line 2, column 1: PL/SQL: SQL Statement ignored ORA-06550: line 6, column 1: PLS-00103: Encountered the symbol "MERGE" 06550. 00000 - "line %s, column %s:\n%s" *Cause: Usually a PL/SQL compilation error. *Action:
Can someone explain why it is not working, please?
Thank you,