REFERENCING OLD AS OLD NEW AS NEW FOR EACH Row
CREATE OR REPLACE TRIGGER TRI_DELETE_INFO AFTER DELETE ON T_INFO_2012 REFERENCING OLD AS OLD NEW AS NEW FOR EACH ROW DECLARE V_SQLERRM VARCHAR2(200); BEGIN DELETE FROM T_INFO_2013 WHERE CODE = :OLD.CODE; --COMMIT; 触发器中不可以使用COMMIT; EXCEPTION WHEN OTHERS THEN V_SQLERRM := '触发器 TRI_DELETE_INFO 出错:' || SQLERRM; INSERT INTO PROCEDURE_LOG (ERRMSG, ERRDATE) VALUES (V_SQLERRM, SYSDATE); END;
1、For each row的意义是:在一次操作表的语句中,每操作成功一行就会触发一次;不写的话,表示是表级触发器,则无论操作多少行,都只触发一次;
2、REFERENCING OLD 和 REFERENCING NEW 的含义不同,具体取决于触发器是行级还是语句级触发器。对于行级触发器,REFERENCING OLD 子句允许引用更新或删除之前行中的值,REFERENCING NEW 子句允许引用已插入或更新的值。在 BEFORE 和 AFTER 触发器中可以引用 OLD 和 NEW 行。REFERENCING NEW 子句允许在插入或更新操作发生之前在 BEFORE 触发器中修改新行
3、:NEW 和:OLD使用方法和意义,new 只出现在insert和update时,old只出现在update和delete时。在insert时new表示新插入的行数据,update时new表示要替换的新数据、old表示要被更改的原来的数据行,delete时old表示要被删除的数据。
begin前面出现的new,old不加冒号,begin和end之间出现的new和old都要在前面加上":"。
REFERENCING OLD AS OLD NEW AS NEW
这样写之后就可以在begin end直接直接使用别名来引用。
相关推荐
CREATE TRIGGER select_t1 SELECT ON t1 REFERENCING OLD AS old FOR EACH ROW WHEN (name = 'Bill') (INSERT INTO t2 (id) VALUES (old.id)); 触发器修改与删除 触发器修改语法如下: ALTER TRIGGER <触发器名> ...
在触发器中,`NEW`和`OLD`是两个特殊变量,用于访问触发器操作所涉及的行。对于`INSERT`操作,`NEW`变量包含即将插入(`BEFORE`触发器)或已插入(`AFTER`触发器)的数据。在`UPDATE`操作中,`OLD`变量保存原始数据...
- **REFERENCING NEW AS new OLD AS old**:提供对新行(NEW)和旧行(OLD)的引用,这对于处理插入和删除非常有用。 - **FOR EACH ROW**:指示触发器将针对每一条受影响的记录进行操作。 - **WHEN (condition)**:...
REFERENCING OLD AS oldRate NEW AS newRate FOR EACH ROW MODIFY DB2SQL SET newRate.status = CASE WHEN newRate.rate >= (SELECT MAX(rate) FROM rateHistory WHERE id = newRate.id) THEN 'highest' WHEN new...
REFERENCING OLD AS o NEW AS n FOR EACH ROW INSERT INTO audit VALUES ( CURRENT_TIMESTAMP, 'Employee ' || o.empno || ' salary changed from ' || CHAR(o.salary) || ' to ' || CHAR(n.salary) || ' by ' ||...
REFERENCING OLD AS old_value NEW AS new_value FOR EACH ROW WHEN (NEW.department_id <> 80) BEGIN :new_value.commission_pct := 0; END; ``` 这个触发器在`employees`表上定义,当有插入或更新操作涉及到`...
其中,trigger_name是触发器的名称,BEFORE、AFTER和INSTEAD OF分别指定触发器的执行时机,triggering_event指定触发器的事件,referencing_clause指定触发器的引用,WHEN指定触发器的条件,FOR EACH ROW指定触发器...
[REFERENCING [NEW AS new_row_name] [OLD AS old_row_name]] [FOR EACH ROW] [WHEN (condition)] [DECLARE variable_declaration] BEGIN statements; [EXCEPTION exception_handlers] END [trigger_name]; ``` ...
语法格式为:CREATE [OR REPLACE] TRIGGER trigger_name {{BEFORE | AFTER} {INSERT | DELETE | UPDATE} [OF column[, column[, column…]]] ON {table_name | view_name} [REFERENCING {OLD [AS] old_name | NEW ...
CREATE or replace TRIGGER T_userupdateT BEFORE update ON T_user REFERENCING OLD AS old NEW AS N_ROW FOR EACH ROW DECLARE U_xtfidemp1 varchar(36); u_xtempcode1 varchar(20); u_xtempcodeCount int:=0; ...
[REFERENCING {OLD AS old_name | NEW AS new_name}] [FOR EACH ROW] [WHEN trigger_condition] trigger_body; ``` 其中,`trigger_name`是触发器的名称,`INSERT | DELETE | UPDATE`定义触发事件,`table_name | ...
[REFERENCING {OLD [AS] old | NEW [AS] new | PARENT as parent}] [FOR EACH ROW] [WHEN condition] trigger_body; ``` #### 五、示例分析 以下是一些触发器相关的示例代码,可以帮助更好地理解触发器的应用场景...
[REFERENCING {OLD [AS] old_name|NEW [AS] new_name}] [FOR EACH ROW] [WHEN trigger_condition] trigger_body; ``` - `trigger_name` 是触发器的唯一标识。 - `BEFORE`, `AFTER`, 或 `INSTEAD OF` 定义触发器...
REFERENCING OLD AS old NEW AS new FOR EACH ROW DECLARE -- 变量声明 BEGIN -- 触发器逻辑 END; ``` 触发器可以设置为在数据操作之前或之后执行,也可以针对每一行数据触发。 以上是对Oracle存储过程及触发器...
REFERENCING OLD AS old_value NEW AS new_value WHEN () BEGIN END; ``` 2. 触发器的应用场景 - 数据完整性约束:当直接的约束无法满足业务规则时,例如,需要在插入新记录时检查多条记录间的关联条件。 - 日志...
[REFERENCING {OLD [AS] old | NEW [AS] new| PARENT as parent}] [FOR EACH ROW] [WHEN condition] trigger_body; ``` 其中,`BEFORE`和`AFTER`指明触发时间,`REFERENCING`子句允许为OLD和NEW值定义别名,`FOR ...
[REFERENCING {OLD [AS] old | NEW [AS] new| PARENT as parent}] [FOR EACH ROW] [WHEN condition] PL/SQL_BLOCK | CALL procedure_name ``` 触发器的使用增加了数据库的复杂性,因此需要谨慎设计和管理,以避免...