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

后端 未结 12 1388
南旧
南旧 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 07:51

    From http://www.praetoriate.com/oracle_tips_upserts.htm:

    "In Oracle9i, an UPSERT can accomplish this task in a single statement:"

    INSERT
    FIRST WHEN
       credit_limit >=100000
    THEN INTO
       rich_customers
    VALUES(cust_id,cust_credit_limit)
       INTO customers
    ELSE
       INTO customers SELECT * FROM new_customers;
    

提交回复
热议问题