2016-02-05 35 views
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_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; 

它的建立,但是當我執行它不會工作參數m_internalrequester_idM_InternalRequesterLine獲取數據到M_InventoryLine。有什麼問題,我該如何解決?

回答

0

這是BEFORE UPDATE根據這一宣言觸發:

create or replace trigger TG_AI_M_INVENTORYSN 
before update on m_inventory 

所以觸發器只是之前更新語句觸發。


IF語句使用INSERTING謂詞來檢查,如果觸發後或INSERT語句之前被解僱。

if inserting then .... 

因爲觸發只更新之前發射,插入謂詞始終是假的,永遠不會執行THENEND IF之間的代碼。