2

创建了以下 VendorAccount 表

VendorAccount

(Ven_AccountId, 
  Ven_RegNo,   
  Ven_Invoice_RefNo,    
  TotalAmount,
  Paid_ToVen ,    
  Balance
)

在上表中,TotalAmount 的值来自另一个 Table( Vendor_InvoiceDetails)。TOTALBALANCE 值是通过 POPUP LOV 选择的。

Pad_TOVEN金额从TOTALAMOUNT( ) 中减去。TotalAMount-Pad_TOVEN当我选择TOTALAMOUNT它时,它会给我旧TOTAL VALUE的,如下图所示。 在此处输入图像描述

我想要更新的值。当我选择 TotalAmount 时,它应该根据新条目的列中的Ven_Invoice_RefNo2300为我提供新的更新值。TotalAmount下面是触发器,但它有休闲错误

错误: PLS-00103: Encountered the symbol "DECLARE" when expecting one of the following: begin function pragma procedure subtype type <an identifier> <a double-quoted delimited-identifier> current curs

扳机:

create or replace trigger "VENDORACCOUNT_T2"
BEFORE
insert or update or delete on "VENDORACCOUNT"
for each row
begin
DECLARE new_balance INT; 
DECLARE new_total INT;
DECLARE new_paid INT;

   SELECT balance INTO old_balance,
   total INTO old_total,
       PAID_TOVEN INTO new_paid
   FROM vendoraccount
   WHERE ven_regno = new.ven_regno
   AND VEN_INVOICE_REFNO = new.VEN_INVOICE_REFNO;

   UPDATE vendoraccount SET TOTALAMOUNT = old_total + old_balance - new_paid,
   balance = TOTALAMOUNT - new_paid
   WHERE VEN_REGNO= new.VEN_REGNO
   AND VEN_INVOICE_REFNO = new.VEN_INVOICE_REFNO;

end;
4

2 回答 2

1

据我所知,有五件事要做:

  1. 将开始移动到“声明”行下方。
  2. 只使用一个“声明”关键字。
  3. 声明 old_balance。
  4. 声明 old_total。
  5. 只是一个“进入”。

    create or replace trigger "VENDORACCOUNT_T2"
    BEFORE
    insert or update or delete on "VENDORACCOUNT"
    for each row
    DECLARE new_balance INT; 
            new_total INT;
            new_paid INT;
            old_balance INT;
            old_total INT;
    begin
    
    SELECT balance, total, PAID_TOVEN 
    INTO old_balance, old_total, new_paid
    FROM vendoraccount
    WHERE ven_regno = new.ven_regno
    AND VEN_INVOICE_REFNO = new.VEN_INVOICE_REFNO;
    
    UPDATE vendoraccount SET TOTALAMOUNT = old_total + old_balance - new_paid,
    balance = TOTALAMOUNT - new_paid
    WHERE VEN_REGNO= new.VEN_REGNO
    AND VEN_INVOICE_REFNO = new.VEN_INVOICE_REFNO;
    end;
    
于 2013-02-12T19:50:40.333 回答
0

您应该在“开始”之前移动声明部分

于 2012-12-05T10:30:02.197 回答