關於ORACLE的TRIGGER的執行(100分)

  • 主题发起人 主题发起人 Teikini
  • 开始时间 开始时间
T

Teikini

Unregistered / Unconfirmed
GUEST, unregistred user!
我編了幾個TRIGGER﹐現有這個TRIGGER不執行﹐不知何故。
它的預想目的是當有記錄往TRADELINEITEMLOG中追加時﹐
同時更新或追加數據到Z01_STOCK中﹐代碼如下﹐各位給看看﹕
create or replace trigger TRD_LineItem_UPD_Z01
after insert on TRADELINEITEMLOG
for each row

DECLARE
shop number(5);
shohin_cd varchar2(13);
T_AREA varchar2(3);
yyyy number(4);
mm number(2);
cnt number(2);
temp number(6);
PRC_SUM_SURYO number(10,2);
PRC_SUM_PRICE number(9);
DLV_SUM_SURYO number(10,2);
DLV_SUM_PRICE number(9);
ODR_SUM_SURYO number(10,2);
ODR_SUM_PRICE number(9);
ADV_SUM_SURYO number(10,2);
DMG_SUM_SURYO number(10,2);
DIV_SUM_SURYO number(10,2);
CUR_PRC_SURYO number(10,2);
CUR_PRC_PRICE number(9);
CUR_DLV_SURYO number(10,2);
CUR_DLV_PRICE number(9);
CUR_ODR_SURYO number(10,2);
CUR_ODR_PRICE number(9);
CUR_ADV_SURYO number(10,2);
CUR_DMG_SURYO number(10,2);
CUR_DIV_SURYO number(10,2);
LOGICAL_STOCK number(10,2);
REAL_STOCK number(10,2);
IVENTORY_DT DATE;
VALUATION_PRICE NUMBER(10, 2);

BEGIN
select TRANAREA, RECEIPTNO INTO T_AREA, temp from TRADELOG T1
WHERE T1.BUSINESSDATE = :new.BUSINESSDATE
AND T1.NODENO = :new.NODENO
AND T1.TRADESEQNO = :new.TRADESEQNO;

IF :new.ITEMCODE IS NOT NULL THEN
shohin_cd := SUBSTRB(:new.ITEMCODE,1,13);
ELSE
shohin_cd := :new.CATEGORYCODE;
END IF;

IF (T_AREA = 100) OR (T_AREA = 102)
OR (T_AREA = 110) OR (T_AREA = 112) THEN

select M02_SHOP_CD into shop from M02_SHOP;
select to_char(sysdate,'yyyy'),to_char(sysdate,'mm') into yyyy,mm from
dual;

select count(*) into cnt from Z01_STOCK
where Z01_SHOP_CD = shop and Z01_YEAR = yyyy and Z01_MONTH = mm
and Z01_SHOHIN_CD = shohin_cd;

IF cnt > 0 THEN
select Z01_LOGICAL_STOCK into LOGICAL_STOCK from Z01_STOCK
where Z01_SHOP_CD = shop and Z01_YEAR = yyyy and Z01_MONTH = mm
and Z01_SHOHIN_CD = shohin_cd;

IF T_AREA = 100 THEN
LOGICAL_STOCK := LOGICAL_STOCK + :new.QUANTITY;
ELSE
LOGICAL_STOCK := LOGICAL_STOCK - :new.QUANTITY;
END IF;

update Z01_STOCK set
Z01_LOGICAL_STOCK = LOGICAL_STOCK,
Z01_UPD_DT = sysdate
where Z01_SHOP_CD = shop and Z01_YEAR = yyyy and Z01_MONTH = mm
and Z01_SHOHIN_CD = shohin_cd;
ELSE
IF T_AREA = 100 THEN
LOGICAL_STOCK := LOGICAL_STOCK + :new.QUANTITY;
ELSE
LOGICAL_STOCK := LOGICAL_STOCK - :new.QUANTITY;
END IF;

insert into Z01_STOCK (
Z01_SHOP_CD,Z01_YEAR,Z01_MONTH,Z01_SHOHIN_CD,
Z01_PRC_SUM_SURYO,Z01_PRC_SUM_PRICE,
Z01_DLV_SUM_SURYO,Z01_DLV_SUM_PRICE,
Z01_ODR_SUM_SURYO,Z01_ODR_SUM_PRICE,
Z01_ADV_SUM_SURYO,Z01_DMG_SUM_SURYO,Z01_DIV_SUM_SURYO,
Z01_CUR_PRC_SURYO,Z01_CUR_PRC_PRICE,
Z01_CUR_DLV_SURYO,Z01_CUR_DLV_PRICE,
Z01_CUR_ODR_SURYO,Z01_CUR_ODR_PRICE,
Z01_CUR_ADV_SURYO,Z01_CUR_DMG_SURYO,Z01_CUR_DIV_SURYO,
Z01_LOGICAL_STOCK,Z01_REAL_STOCK,Z01_IVENTORY_DT,
Z01_VALUATION_PRICE,Z01_UPD_DT
) values (
shop,yyyy,mm,shohin_cd,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
LOGICAL_STOCK,0,NULL,
0,sysdate
);
END IF;
END IF;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
END;
/
 
cj准知道!
 
問題已解決﹐換個話題吧﹕
怎樣調試ORACLE 的Procedure 和 Trigger.
歡迎灌水。
 
buy oracle developer 2000:
there is a [precedure builder] can debug your procedure and trigger.

you can download it from http://technet.oracle.com


ORACLE CHINA
 
cpp说的也对,购买d2000肯定挺好的,如果没买,可以在trigger中添加数据库返回
信息来看如 dbms_output.put_line()等函数,返回一些信息一般的程序都可搞定,
 
接受答案了.
 
后退
顶部