Oracle: how to UPSERT (update or insert into a table?)

后端 未结 12 1562
南旧
南旧 2020-11-22 07:18

The UPSERT operation either updates or inserts a row in a table, depending if the table already has a row that matches the data:

if table t has a row exists          


        
12条回答
  •  一整个雨季
    2020-11-22 08:05

    The dual example above which is in PL/SQL was great becuase I wanted to do something similar, but I wanted it client side...so here is the SQL I used to send a similar statement direct from some C#

    MERGE INTO Employee USING dual ON ( "id"=2097153 )
    WHEN MATCHED THEN UPDATE SET "last"="smith" , "name"="john"
    WHEN NOT MATCHED THEN INSERT ("id","last","name") 
        VALUES ( 2097153,"smith", "john" )
    

    However from a C# perspective this provide to be slower than doing the update and seeing if the rows affected was 0 and doing the insert if it was.

提交回复
热议问题