Updating Oracle Table from SQL SERVER

235 Views Asked by At

I am trying to update an oracle table from sql server using linked server openquery method

 UPDATE   target
SET "FIRST_NAME"  =source.FIRST_NAME    ,
    "LAST_NAME"  =source.LAST_NAME  
FROM  (
SELECT * FROM OPENQUERY([RemoteServer],'SELECT * FROM table1'))  target
INNER JOIN    
table2 source
ON 
    target.PK = source.PK

I am getting follwoing error: Cannot update row as the data in the database has changed.

I am able to fetch data using select statement.

SELECT * FROM OPENQUERY([RemoteServer],'SELECT * FROM table1')  target
INNER JOIN    table2 source
ON 
    target.PK = source.PK

WHEN I specify any value of PK then update works. For e.g

UPDATE   target
    SET
    "FIRST_NAME"  =source.FIRST_NAME    ,
    "LAST_NAME"  =source.LAST_NAME  
FROM  (
SELECT * FROM OPENQUERY([RemoteServer],'SELECT * FROM table1 where PK=1'))  target
INNER JOIN    
table2 source
ON 
    target.PK = source.PK

The above query works and 1 row is updated. But my requirement is to update all row sets from table2(SQL SERVER) to table1(Remote Oracle Table).

I have noticed insert works.

0

There are 0 best solutions below