[英]Oracle PL/SQL Trigger: update/insert with where condition
Maybe it's quite easy but I don't get ahead. 也许这很容易,但我没有前进。 The table B
contains two fields: product_no NUMBER
and product VARCHAR2
. 表B
包含两个字段: product_no NUMBER
和product VARCHAR2
。 What the trigger should do is to insert a corresponding product description from BP-table
in which you also have the fields product_no
and product
. 触发器应该执行的操作是从BP-table
中插入相应的产品描述,在该BP-table
中您还具有字段product_no
和product
。 Eg you enter 20 in B.product_no
then it should be automatically entered the right product from BP-Table
. 例如,您在B.product_no
输入20,则应该从BP-Table
自动输入正确的产品。 Oracle version is 11g. Oracle版本是11g。
CREATE OR REPLACE TRIGGER A.trigger_on_B
AFTER INSERT OR UPDATE
ON A.B FOR EACH ROW
DECLARE
varProduct varchar(20);
BEGIN
SELECT bp.report_info
into varProduct
from bp,
B
where bp.product_no = B.product_no;
insert into B (product) values(varProduct) ;
exception
when others then NULL;
END;/
You can user pseudo records :new, :old, to make it work: 您可以使用伪记录:new,:old来使其工作:
CREATE OR REPLACE TRIGGER A.trigger_on_B
AFTER INSERT OR UPDATE
ON A.B FOR EACH ROW
DECLARE
varProduct varchar(20);
BEGIN
SELECT bp.report_info
into varProduct
from bp
where bp.product_no = :new.product_no;
insert into B (product) values(varProduct) ;
exception
when others then NULL;
END;
when others then NULL;
when others then NULL;
摆脱该行when others then NULL;
this is unappropriated you can't hide any exceptions. 这是不适当的,您无法隐藏任何异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.