I see a lot of similar questions already answered including here, here and here. The list goes on.
What makes mine different? These other questions seem to be very simple, one line sql statements. I have a more complex merge statement that spans multiple lines and no matter how I have tried to put the statement together it gives me a compilation error. Below is one such attempt.
It is a long statement, the only dynamic parts are 2 nonconsecutive lines at the very beginning as shown below. I have tried to make the whole statement a string and execute it, but I get an error that the string is too long, plus this makes it very hard to read so it is undesirable. I have also tried breaking up the 2 parts that require dynamic sql into 2 execute immediate blocks, but that throws a compilation error as well.
My code
create or replace procedure table_sync(
table_name in varchar2,
source_node in varchar2
)
is
begin
execute immediate
'merge into ' || table_name || ' dest' /* ---- first line ---- */
using (select date_time, version_date, data_entry_date, value
'from username.' || table_name || '@' || source_node /* ---- second line ---- */
where data_entry_date < (sysdate - 10)) src
on ( dest.date_time = src.date_time and
dest.version_date = src.version_date
)
when matched then
update
set
dest.data_entry_date = src.data_entry_date,
dest.value = src.value
where
(case
.
.
.
Is there a way to put combine this dynamic statement?
Thank you