What is wrong with this merge statement?
Question
I am relatively new to oracle and have written the merge statment below which produces an "ora-00904 error vwe_cpr_info.rin_per_id invalid identifier" message when I run it.
I have checked and the view and column names are correct, I do have permissions to access the view and I am not trying to update a field that is being used in a join.
I have looked at this for so long now I think I have stopped seeing it, any advice would be most welcome. It is in an Oracle 9i environment.
MERGE INTO vws_art_alert
USING (
SELECT rin_date_unreg, rin_per_id
FROM vwe_cpr_info
WHERE rin_date_unreg >= '27-SEP-11'
AND rin_date_unreg <= '13-JAN-12')
ON (vws_art_alert.art_per_id = vwe_cpr_info.rin_per_id
AND art_alert = 'AL02'
AND art_inactive_on IS NULL)
WHEN MATCHED THEN
UPDATE SET vws_art_alert.art_inactive_on = vwe_cpr_info.rin_date_unreg;
Solution
You need an alias for the "using" clause. Try this:
MERGE INTO vws_art_alert
USING (
SELECT rin_date_unreg, rin_per_id
FROM vwe_cpr_info
WHERE rin_date_unreg >= '27-SEP-11'
AND rin_date_unreg <= '13-JAN-12') t
ON (vws_art_alert.art_per_id = vwe_cpr_info.rin_per_id
AND art_alert = 'AL02'
AND art_inactive_on IS NULL)
WHEN MATCHED THEN
UPDATE SET vws_art_alert.art_inactive_on = t.rin_date_unreg;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow