ORA-04088:执行触发器'OES2.T_UPDATE_ORDERS_GROSS'

时间:2018-07-11 03:01:08

标签: plsql triggers

我创建了触发器: -删除触发器t_update_orders_gross

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表中的插入语句的过程,该语句应触发触发程序:

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_grossSales时出现以下错误:

  

从第62行开始的错误-   开始p_update_orders_grossSales;结束;   错误报告 -   ORA-01422:精确获取返回的行数超过了请求的行数   ORA-06512:位于“ OES2.T_UPDATE_ORDERS_GROSS”第5行   ORA-04088:执行触发器'OES2.T_UPDATE_ORDERS_GROSS'时出错   ORA-06512:在“ OES2.P_UPDATE_ORDERS_GROSSSALES”,第22行   ORA-06512:在第1行   01422. 00000-“精确提取返回的行数超过了请求的行数”   *原因:精确提取中指定的数字小于返回的行。   *操作:重写查询或更改请求的行数

为什么会生成错误错误代码,如果我一次在触发器工作时插入一行,但是我想用一个过程插入很多记录,并且应该触发触发器来计算在订单表中插入的行的小计在orders_update表中插入行。

1 个答案:

答案 0 :(得分:1)

当“ select into”返回多于1行时,Oracle引发错误ORA-01422。在这种情况下,由于没有WHERE,从订单表中进行选择将返回订单表中的每一行。您需要添加与更新订单语句相同的where子句。您可能需要准备“未找到数据异常”。

Belayer