I have two tables in the following structure:
TABLE 1:
ITEM | JAN | FEB | MAR | APR | MAY | JUN
___________________________________________
Item A| 50 | 10 | 25 | NULL| NULL| NULL
Item C| 26 | 20 | 23 | NULL| NULL| NULL
Item B| 25 | 30 | 22 | NULL| NULL| NULL
TABLE 2:
ITEM | JAN | FEB | MAR | APR | MAY | JUN
___________________________________________
Item A| NULL| NULL| NULL| 32 | 26 | 12
Item B| NULL| NULL| NULL| 25 | 24 | 10
Item D| NULL| NULL| NULL| 22 | 35 | 14
I am trying to merge the tables, to get the following result:
ITEM | JAN | FEB | MAR | APR | MAY | JUN
___________________________________________
Item A| 50 | 10 | 25 | 32 | 26 | 12
Item B| 25 | 30 | 22 | 25 | 24 | 10
Item C| 26 | 20 | 23 | NULL| NULL| NULL
Item D| NULL| NULL| NULL| 22 | 35 | 14
I tried the following query:
MERGE INTO TABLE1 a USING (
SELECT REBATE_ITEM, JAN, FEB, MAR, APR, MAY FROM TABLE2
) b
ON (TRIM(a.ITEM) = TRIM(b.ITEM) AND a.JUN is null)
WHEN MATCHED THEN
UPDATE SET
a.APR = b.APR,
a.MAY = b.MAY,
a.JUN = b.JUN
I get the following result: SQL Error: ORA-38104: Columns referenced in the ON Clause cannot be updated:
Any ideas on how I can accomplish this merge/join/whatever?
MERGEupdates a table, your description sounds as if simply want a query that returns the desired result. What is it exactly that you want to achieve?