Hi i have created the following SQL statement to help me merge data from one table into another table. The following code seems t o be working fine.
MERGE INTO FTOURSTATS ts
USING (SELECT * FROM guest_tour) t
ON (t.TOUR_ID = ts.TOURID AND t.START_DATETIME = (SELECT CALENDARDATE FROM FTIMEPERIOD tp WHERE ts.TIMEID = tp.TIMEID) AND ((SELECT SYSDATE FROM DUAL) - t.START_DATETIME ) < 7)
WHEN MATCHED THEN
UPDATE SET
ts.TOTALREVENUE = ts.TOTALREVENUE + ((SELECT COST_PER_DAY FROM TOUR WHERE TOUR_ID = t.TOUR_ID) * 0.1),
ts.TOTALTOURISTS = ts.TOTALTOURISTS + t.GROUP_SIZE
However when i enter the following code
WHEN NOT MATCHED THEN
INSERT VALUES( (SELECT TIMEID FROM FTIMEPERIOD WHERE CALENDARDATE = t.TOUR_ID),1, t.TOUR_ID,(SELECT COST_PER_DAY FROM TOUR WHERE TOUR_ID = t.TOUR_ID) * 0.1,t.group_size);
I I get the following error
Error at Command Line : 10 Column : 69
Error report -
SQL Error: ORA-00904: "T"."TOUR_ID": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
But all of the identifiers worked in the section above. Is this maybe becuase of a scope issue?. Any help would be much appreciated.I want both the Matched and the NOT Matched to do something. They marked this as a duplicate for when nopthing must be done in the matched but this does not help me at all