I am trying to use MERGE in a procedure and in the insert values I would like to use a query using the USING_SET
The MERGE looks like below:
MERGE INTO N_CUSTOMER dest
USING S_customer src
ON (dest.CUSTOMER_ID = src.CUSTOMER_ID)
WHEN
MATCHED THEN
update set
dest.DATE_OF_BIRTH = src.S_BIRTHDATE,
dest.GENDER = src.S_GENDER,
dest.NAME = src.S_NAME
WHEN NOT MATCHED THEN
INSERT (DATE_OF_BIRTH, GENDER, NAME, TOTAL_FOO_COUNT)
VALUES (src.S_BIRTHDATE, src.S_GENDER, src.S_NAME,
(select count(f.FOO_ID) from S_FOO f where f.CUSTOMER_ID = src.CUSTOMER_ID));
The error that I got is:
invalid SQL Error: ORA-00904: "SRC"."CUSTOMER_ID": invalid identifier in the subquery (select count(f.FOO_ID) from S_FOO f where f.CUSTOMER_ID = src.CUSTOMER_ID).
Some how oracle cannot recognize the "src" inside the Subquery. Any ideas?