Implement only the inserted line in Trigger

xiaoxiao2021-03-06  87

Do a table's INSERT TRIGGER, the purpose is to modify the field of the inserted row.

Create or Replace Trigger TR_RME_SLOTBEFORE

INSERT on RME_SLOT

For Each Row

Begin

IF (: new.position> = 0 and: new.position <10) THEN

: New.slot_name: = '0' || to_Char (: new.position);

Else

: NEW.SLOT_NAME: = to_CHAR (: new.position);

END IF;

END;

You need to modify the insert line before inserting; UPDATE statements do not need to be used in Trigger implementations

At the same time, if you want to implement the modification of this table in TRIGGER, you need to write:

Create or Replace Trigger TR_RME_SLOT AFTER

INSERT on RME_SLOT

For Each Row

Declare

Pragma autonomous_transaction;

Begin

IF (: new.position> = 0 and: new.position <10) THEN

Update RME_SLOT SET SLOT_NAME = '0' || to_char (: new.position) where slot_id =: new.slot_id;

Else

Update RME_SLOT SET SLOT_NAME = to_CHAR (: new.position) where slot_id =: new.slot_id;

END IF;

COMMIT;

END;

Pay attention to a Declare, while at the end of TRIGGER, you need commiti

转载请注明原文地址:https://www.9cbs.com/read-122598.html

New Post(0)