合并到没有插入预期的行

Merge into is not inserting the expected rows

MERGE
INTO             cars2 
USING            abc 
ON ( 
                                  cars2.vehicleid = abc.vehicleid) 
WHEN NOT matched THEN 
INSERT 
       ( 
              cars2.vehicleid, 
              cars2.brand, 
              cars2.model, 
              cars2.vehicle_type, 
              cars2.fuel_type, 
              cars2.transmission_type, 
              cars2.gearbox, 
              cars2.drive_type, 
              cars2.vehicle_number, 
              cars2.price 
       ) 
       >>VALUES 
       ( 
              abc.vehicleid, 
              abc.brand, 
              abc.model, 
              abc.vehicle_type, 
              abc.fuel_type, 
              abc.transmission_type, 
              abc.gearbox, 
              abc.drive_type, 
              abc.vehicle_number, 
              abc.price 
       ) 
WHERE  abc.vehicleid < 1000;

当我执行上面的代码时,它说 0 行 inserted.But 实际上它应该插入两行。任何人都可以帮我解决这个问题吗?

select VEHICLEID from abc where vehicleid > 1000;

输出:-

VEHICLEID
9977
9978

认为您需要进行细微的修改。您的 where 子句位置错误。

MERGE
INTO cars2 
USING (
   select * from abc WHERE  abc.vehicleid < 1000) abc
ON (cars2.vehicleid = abc.vehicleid) 
WHEN NOT matched THEN 
INSERT 
       ( 
              cars2.vehicleid, 
              cars2.brand, 
              cars2.model, 
              cars2.vehicle_type, 
              cars2.fuel_type, 
              cars2.transmission_type, 
              cars2.gearbox, 
              cars2.drive_type, 
              cars2.vehicle_number, 
              cars2.price 
       ) 
       >>VALUES 
       ( 
              abc.vehicleid, 
              abc.brand, 
              abc.model, 
              abc.vehicle_type, 
              abc.fuel_type, 
              abc.transmission_type, 
              abc.gearbox, 
              abc.drive_type, 
              abc.vehicle_number, 
              abc.price 
       )