2

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

我看过了before insert。有没有办法根据该块内的条件取消插入?

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

解决此问题的最佳方法是什么?

4

2 回答 2

4

使用 MERGE 语句而不是 INSERT。

于 2012-06-13T20:36:48.200 回答
0

使用合并语句。

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

于 2016-04-05T14:36:25.740 回答