在SQL触发器中绑定变量错误

时间:2014-03-27 16:29:35

标签: sql plsql

这是我的触发器。以下错误。  45 / SP2-0552:绑定变量" OLD"没有宣布。 我无法找到错误。我已经尝试了几次但失败了。我已经声明了每个变量,但错误显示出来。有人请帮助我。

drop trigger DELETE_Single_food
CREATE OR REPLACE TRIGGER DELETE_Single_food
BEFORE DELETE ON SingleFoodOrder
FOR EACH ROW


declare

f_price number;
old_bill   number;
f_quantity     number;
p_bill  number;
foodID number;
orderID number;
order_date Date;
s_date Date;
f_date Date;
f_dis  number;
a number;
b number;
c number; 
BEGIN  
    IF :old.H_delivery_ID is not NULL then
        foodID := :old.Fooditem_ID;
        orderID := :old.H_delivery_ID;
        f_quantity := :old.Quantity;
        select bill into old_bill from HomeDelivery where H_delivery_ID =orderID ;
        select price into f_price from Food_Item where Fooditem_ID = foodID;
        select discount_percentage into f_dis from Food_Item where Fooditem_ID = foodID;
        select start_date into s_date from Food_Item where Fooditem_ID = foodID;
        select deadline into f_date from Food_Item where Fooditem_ID = foodID;
        select H_delivery_request into order_date from HomeDelivery where H_delivery_ID =orderID;
        if f_dis is not NULL then

            if (order_date >= s_date  and order_date<=f_date) then
                 a := f_dis/100;
                 b := f_price*a ;
                 c := f_price-b;

                 p_bill := old_bill-( c*f_quantity); 
                 update HomeDelivery set bill = p_bill where H_delivery_ID = orderID;                 
            else
                 p_bill := old_bill-(f_price*f_quantity);
                 update HomeDelivery set bill = p_bill where H_delivery_ID = orderID;
            end if;
        else  
            p_bill := old_bill-(f_price*f_quantity);
            update HomeDelivery set bill = p_bill where H_delivery_ID = orderID;  
        end if;      
END;
/

1 个答案:

答案 0 :(得分:0)

问题不在你的变量声明中。我认为你没有关闭你的主要IF声明:

IF :old.H_delivery_ID is not NULL then

我没有看到那个END IF。添加END IF;在END之前; 如果这不起作用,您将需要进行一些调试。尝试只在开始块中保留该语句。

CREATE OR REPLACE TRIGGER DELETE_Single_food
BEFORE DELETE ON SingleFoodOrder
FOR EACH ROW
BEGIN  
    IF :old.H_delivery_ID is not NULL then
        null;
    END IF;
END;
/

看看是否编译。然后添加其余代码以查看它的中断位置。 希望这有帮助!