I am using the following merge statement to update a table but it raises the error;
ORA-02012: missing USING keyword
The documentation link states The keyword USING did not follow the CONNECT TO clause in a CREATE DATABASE LINK statement. Specify the USING clause after the CONNECT TO clause.
merge into GlassesGesDev.VEHICLEACCESSORYDETAILS current
using VehicleAccessoryTest new
on (current.VehicleId = new.Vehicle and current.OptionCode = new.OptionCode and current.EffectiveDate = new.EffectiveDate)
when not matched then
insert (VehicleId, OptionCode, EffectiveDate, OptionType, OptionPriceNew, OptionPriceDepreciated, Deleted, CreatedDate, CreatedUser, ModifiedDate, ModifiedUser, ImportedToGuideWire)
values (new.VehicleCode, new.OptionCode, new.Effective_Date, new.OptionType, new.RrpAmount, new.RetailAmount, 'N', current_timestamp, USER, current_timestamp, USER, 'N')
when matched then
update
set OptionType = new.OptionType,
OptionPriceNew = new.RrpAmount,
OptionPriceDepreciated = new.RetailAmount,
ModifiedDate = current_timestamp,
ModifiedUser = USER;
I have reviewed the script and read several articles on using the merge statement without determining what could be causing the error.
The data base is running on Oracle Database 19c Standard Edition 2 Release 19.0.0.0.0 - Production.
Change CURRENT to "C" (or similar)
SQL> merge into GlassesGesDev.VEHICLEACCESSORYDETAILS current
2 using VehicleAccessoryTest new
3 on (current.VehicleId = new.Vehicle and current.OptionCode = new.OptionCode and current.EffectiveDate = new.EffectiveDate)
4 when not matched then
5 insert (VehicleId, OptionCode, EffectiveDate, OptionType, OptionPriceNew, OptionPriceDepreciated, Deleted, CreatedDate, CreatedUser, ModifiedDate, ModifiedUser, ImportedToGuideWire)
6 values (new.VehicleCode, new.OptionCode, new.Effective_Date, new.OptionType, new.RrpAmount, new.RetailAmount, 'N', current_timestamp, USER, current_timestamp, USER, 'N')
7 when matched then
8 update
9 set OptionType = new.OptionType,
10 OptionPriceNew = new.RrpAmount,
11 OptionPriceDepreciated = new.RetailAmount,
12 ModifiedDate = current_timestamp,
13 ModifiedUser = USER;
merge into GlassesGesDev.VEHICLEACCESSORYDETAILS current
*
ERROR at line 1:
ORA-02012: missing USING keyword
SQL> merge into GlassesGesDev.VEHICLEACCESSORYDETAILS c
2 using VehicleAccessoryTest new
3 on (c.VehicleId = new.Vehicle and c.OptionCode = new.OptionCode and c.EffectiveDate = new.EffectiveDate)
4 when not matched then
5 insert (VehicleId, OptionCode, EffectiveDate, OptionType, OptionPriceNew, OptionPriceDepreciated, Deleted, CreatedDate, CreatedUser, ModifiedDate, ModifiedUser, ImportedToGuideWire)
6 values (new.VehicleCode, new.OptionCode, new.Effective_Date, new.OptionType, new.RrpAmount, new.RetailAmount, 'N', c_timestamp, USER, c_timestamp, USER, 'N')
7 when matched then
8 update
9 set OptionType = new.OptionType,
10 OptionPriceNew = new.RrpAmount,
11 OptionPriceDepreciated = new.RetailAmount,
12 ModifiedDate = c_timestamp,
13 ModifiedUser = USER;
merge into GlassesGesDev.VEHICLEACCESSORYDETAILS c
*
ERROR at line 1:
ORA-00942: table or view does not exist