我想将数据从一个表获取到另一个表,给定下面的参数。
所以我有 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 Requester
和M_InternalRequesterLine
中记录的数据
我想根据表 m_internalrequester_id
中给出的参数将数据从M_InternalRequesterLine
获取到 M_InventoryLine
M_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;
它已创建,但是当我执行它时它将不起作用。问题是什么,我该如何解决?
以下声明,这是BEFORE UPDATE
触发器:
create or replace trigger TG_AI_M_INVENTORYSN
before update on m_inventory
因此,触发器仅在更新语句之前触发。
IF 语句使用谓词INSERTING
检查触发器是在 INSERT 语句之后还是之前触发的。
if inserting then ....
由于触发器仅在 UPDATE 之前触发,因此 INSERTING 谓词始终为 false,并且永远不会执行 THEN
和 END IF
之间的代码。