为什么触发器伪记录占位符用于触发器主体中的绑定变量而不是 WHEN?
Why are trigger pseudorecords placeholders for bind variables in trigger body but not WHEN?
documentation 指出:
In the trigger_body of a simple trigger or the tps_body of a compound trigger, a correlation name is a placeholder for a bind variable. Reference the field of a pseudorecord with this syntax:
:pseudorecord_name.field_name
In the WHEN clause of a conditional trigger, a correlation name is not a placeholder for a bind variable. Therefore, omit the colon in the preceding syntax.
我的工作示例如下所示:
CREATE OR REPLACE TRIGGER started
BEFORE UPDATE OF mgr_start_date ON department
FOR EACH ROW
WHEN (new.mgr_start_date < old.mgr_start_date)
BEGIN
:new.mgr_start_date := :old.mgr_start_date;
DBMS_OUTPUT.PUT_LINE('Rejected backdate of mgr_start_date.');
END;
为什么绑定变量的伪记录(相关名称)占位符在一种情况下而不是另一种情况下?
"Would the creators of Oracle care to chime in?"
我不是创作者之一,但无论如何我都会加入。
这些伪记录引用不是绑定变量的占位符...
WHEN (new.mgr_start_date < old.mgr_start_date)
... 因为这一行是触发器规范的一部分。它定义触发器触发的条件。它指定的是字段名称而不是值。
这些伪记录引用是占位符...
:new.mgr_start_date := :old.mgr_start_date;
...因为它们引用了新旧版本记录中的实际值。
documentation 指出:
In the trigger_body of a simple trigger or the tps_body of a compound trigger, a correlation name is a placeholder for a bind variable. Reference the field of a pseudorecord with this syntax:
:pseudorecord_name.field_name
In the WHEN clause of a conditional trigger, a correlation name is not a placeholder for a bind variable. Therefore, omit the colon in the preceding syntax.
我的工作示例如下所示:
CREATE OR REPLACE TRIGGER started
BEFORE UPDATE OF mgr_start_date ON department
FOR EACH ROW
WHEN (new.mgr_start_date < old.mgr_start_date)
BEGIN
:new.mgr_start_date := :old.mgr_start_date;
DBMS_OUTPUT.PUT_LINE('Rejected backdate of mgr_start_date.');
END;
为什么绑定变量的伪记录(相关名称)占位符在一种情况下而不是另一种情况下?
"Would the creators of Oracle care to chime in?"
我不是创作者之一,但无论如何我都会加入。
这些伪记录引用不是绑定变量的占位符...
WHEN (new.mgr_start_date < old.mgr_start_date)
... 因为这一行是触发器规范的一部分。它定义触发器触发的条件。它指定的是字段名称而不是值。
这些伪记录引用是占位符...
:new.mgr_start_date := :old.mgr_start_date;
...因为它们引用了新旧版本记录中的实际值。