Oracle Trigger UPDATE instead of INSERT



试图找到一种方法来编写一个 Oracle 触发器,该触发器将在插入之前检查是否在主列中找到匹配项,如果是,则更新行信息而不是插入新行。

我看过before insert.有没有办法根据该块内的标准取消插入?

我也看过使用 instead of 子句,但它需要处理视图。

最好的

方法是什么?

使用 MERGE 语句而不是 INSERT。

使用合并语句。

MERGE INTO <<your table>> t
   USING (<<your list of records - can be the result of a SELECT >>)
   ON ( <<join between table and list of records >>)
WHEN MATCHED THEN
  UPDATE SET << the rows you want to set>>
WHEN NOT MATCHED THEN
  INSERT (<<columns of table>>)
  VALUES (<<value>>)

https://oracle-base.com/articles/9i/merge-statement

最新更新