Plsql ORA-04088:执行触发器“OES2.T\U更新\U订单\U总量”时出错

Plsql ORA-04088:执行触发器“OES2.T\U更新\U订单\U总量”时出错,plsql,triggers,Plsql,Triggers,我创建了触发器: -下拉触发t\u更新\u订单\u总额 create or replace trigger t_update_orders_gross before insert on orders_update for each row declare v_gross int; v_subtotal int; begin select subtotal into v_subtotal from orders; if v_subtotal is null then :new.subtot

我创建了触发器: -下拉触发t\u更新\u订单\u总额

create or replace trigger t_update_orders_gross
before insert on orders_update
for each row
declare
v_gross int;
v_subtotal int;
begin
select subtotal into v_subtotal from orders;
if v_subtotal is null then
    :new.subtotal:=testing(:new.order_no); 
--  testing is a function that will calculate the subtotal for the given 
-- order_no
    update orders set subtotal=:new.subtotal
    where order_no=:new.order_no;
end if;
end;
-调用orders_update表中应触发触发器的insert语句的过程:

create or replace procedure p_update_orders_grossSales
as
v_order_no orders.order_no%type;   
v_order_date orders.order_date%type;
v_ship_date orders.ship_date%TYPE;
v_shipping_method orders.shipping_method%type;
v_tax_status orders.tax_status%type;
v_subtotal orders.subtotal%type;
v_tax_amt orders.tax_amt%type;
v_shipping_charge orders.shipping_charge%type;
v_total_amt orders.total_amt%type;
v_customer_no orders.customer_no%type;
v_employee_no orders.employee_no%type;
v_branch_no orders.branch_no%type;
cursor c1 is select order_no,order_date,ship_date,shipping_method,tax_status, subtotal,tax_amt,shipping_charge,total_amt,customer_no,employee_no,branch_no from orders;

begin
open c1;
loop
    fetch c1 into v_order_no,v_order_date,v_ship_date,v_shipping_method,v_tax_status,v_subtotal,v_tax_amt,v_shipping_charge,v_total_amt,v_customer_no,v_employee_no,v_branch_no;
    exit when c1%notfound;
    insert into orders_update (
            order_no,order_date,ship_date,shipping_method,tax_status, subtotal,tax_amt,shipping_charge,total_amt,customer_no,employee_no,branch_no)
        values (v_order_no,v_order_date,v_ship_date,v_shipping_method,v_tax_status,v_subtotal,v_tax_amt,v_shipping_charge,v_total_amt,v_customer_no,v_employee_no,v_branch_no);
    end loop;
close c1;
end;
/
在执行过程p_update_orders_grossales时,我得到以下错误:

从命令中的第62行开始时出错- 开始订单更新;终止 错误报告- ORA-01422:精确获取返回的行数超过请求的行数 ORA-06512:在OES2.T_更新_订单总额,第5行 ORA-04088:执行触发器“OES2.T\U更新\U订单\U总量”时出错 ORA-06512:在OES2.P_UPDATE_ORDERS_grossales,第22行 ORA-06512:在第1行 142200000-精确提取返回的行数超过请求的行数 *原因:精确提取中指定的行数小于返回的行数。 *操作:重写查询或更改请求的行数


为什么会产生错误,如果我一次插入一行,触发器正在工作,但我想用一个过程插入多条记录,那么在将行插入orders\u update table之前,应该触发触发器来计算order表中插入的行的小计。

当select into返回的行数超过1行时,Oracle会引发错误ORA-01422。在这种情况下,select from orders表将返回orders表中的每一行,因为没有WHERE。您需要添加与update orders语句相同的where子句。您可能需要为“未找到数据”异常做好准备

保护者