0

给定下面的参数,我想从一个表中获取数据到另一个表..

所以我有 4 张桌子,它们是

M_InternalRequester, M_InternalRequesterLine, M_Inventory, M_InventoryLine

M_InternalRequester

-----------------------
m_internalrequester_id 
-----------------------
1001                   

M_InternalRequesterLine

------------------------------------------------------------------------------
m_internalrequesterline_id || m_internalrequester_id || m_product_id || qty || 
------------------------------------------------------------------------------
3001                       || 1001                   || 21001        ||  3  ||
3002                       || 1001                   || 21002        ||  4  ||

M_Inventory

----------------------------------------------------------------------
m_inventory_id || description             || m_internalrequester_id ||
----------------------------------------------------------------------
8001           || Referred from Internal  ||  1001                  ||

M_InventoryLine

--------------------------------------------------------------
m_inventoryline_id || m_inventory_id || m_product_id || qty || 
--------------------------------------------------------------
???????????        ||  8001          ||  ??????????? || ??  ||
???????????        ||  8001          ||  ??????????? || ??  ||

我有以前记录在M_Internal RequesterM_InternalRequesterLine

我想根据表中给出的参数从M_InternalRequesterLineto获取数据M_InventoryLinem_internalrequester_idM_Inventory

我做了一个这样的触发器

create or replace trigger TG_AI_M_INVENTORYSN
before update on m_inventory
for each row
declare
  internalrequester_id number;
  invline_id number;

CURSOR c1 is
select
    M_PRODUCT_ID, QTY
from m_internalrequesterline
where m_internalrequester_id=:new.m_internalrequester_id;

BEGIN

if inserting then 
SELECT M_INTERNALREQUESTER_ID INTO INTERNALREQUESTER_ID FROM M_INTERNALREQUESTER WHERE
m_internalrequester_ID = :new.m_internalrequester_id;

FOR insertline in C1
LOOP
select currentnext into invline_id from AD_Sequence WHERE
name = 'M_Inventoryline';

INSERT INTO M_INVENTORYLINE 

(m_inventoryline_id, m_product_id, qty
)
VALUES 
(invline_id, insertline.m_product_id, insertline.qty);


update AD_Sequence set currentnext=invline_id+1 where name = 'M_Inventoryline';
END LOOP;
END IF;


end;

它是创建的,但是当我执行它时它不起作用。有什么问题,我该如何解决?

4

1 回答 1

0

这是BEFORE UPDATE根据此声明的触发器:

create or replace trigger TG_AI_M_INVENTORYSN
before update on m_inventory

因此触发器仅在更新语句之前触发。


IF 语句使用INSERTING谓词检查触发器是在 INSERT 语句之后还是之前触发。

if inserting then ....

因为触发器仅在 UPDATE 之前触发,所以 INSERTING 谓词始终为假,并且永远不会执行介于THEN和之间的代码。END IF

于 2016-02-05T16:33:11.073 回答