简体   繁体   English

oracle 触发插入后删除

[英]oracle trigger delete after insert

I have a table "person"我有一张桌子“人”

id groupId occupation state
1  5       DIRECTOR   RETIREMENT
2  5       TEACHER    VACATION
3  4       DIRECTOR   ACTIVE

I need a trigger that delete new inserted row if it has the same grupiId, the same occupation and state ACTIVE.我需要一个触发器来删除新插入的行,如果它具有相同的 grupiId、相同的职业和state ACTIVE。 For example: If I insert a row with groupId 4, function Teacher, state wherever - it's OK.例如:如果我在任何地方插入 groupId 为 4、function Teacher、state 的行 - 没关系。 If I insert a row with groupId 4, function Director, state HOLIDAY- it's OK.如果我插入一行 groupId 为 4,function Director,state HOLIDAY - 没关系。 But If I insert a row with groupId 4, function Director, state ACTIVE it should be deleted after insertion但是如果我插入一行 groupId 4, function Director, state ACTIVE 它应该在插入后删除

Don't use a trigger for this.不要为此使用触发器。 Just use a unique constraint or index:只需使用唯一约束或索引:

alter table person add constraint unq_person_groupid_function
    unique (groupid, function);

As a note: function is a poor choice for a column name, because it is a SQL keyword.注意: function是列名的错误选择,因为它是 SQL 关键字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM