我想从一个表到另一个表获取数据,给定以下参数..
所以我有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_InternalRequesterLine
中提供的参数M_InventoryLine
将数据从m_internalrequester_id
提取到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;
它已经创建但是当我执行它时,它不会工作。有什么问题,如何解决?
答案 0 :(得分:0)
根据此声明,这是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
之间的代码。