0
我試過兩種方法。首先,我使用存儲過程在觸發器中調用。錯誤刷新或更新使用觸發器的物化視圖
CREATE OR REPLACE TRIGGER MV_BANK_CODE_UPDATE
AFTER UPDATE OR INSERT OR DELETE OF APPROVAL_STATUS ON BANK_CODES
FOR EACH ROW
BEGIN
SP_UPDATE_MV_BANK_CODES;
END;
/
存儲過程:
CREATE OR REPLACE PROCEDURE SP_UPDATE_MV_BANK_CODES IS
BEGIN
DELETE MV_BANK_CODES;
COMMIT;
INSERT MV_BANK_CODES
(SELECT DISTINCT
bankcodeeo.clearing_area,
bankcodeeo.bank_code,
bankcodeeo.bank_code_id,
bankcodeeo.bank_name,
bankcodeeo.office_code,
bankcodeeo.bank_address,
oldaccounteo.office_code
|| '.'
|| oldaccounteo.gl_account_no
|| '.'
|| oldaccounteo.sl_account_no
|| '.'
|| oldaccounteo.currency_code
|| '.'
|| oldaccounteo.department_code
|| '.'
|| oldaccounteo.working_unit_code
|| '.'
|| oldaccounteo.project_code
AS new_ind_account_no,
/*tcgleo.*/
'9' AS position,
transactioncodeeo.transaction_code,
oldaccounteo.gl_account_no,
oldaccounteo.sl_account_no,
oldaccounteo.currency_code,
oldaccounteo.department_code,
oldaccounteo.working_unit_code,
oldaccounteo.project_code,
oldaccounteo.old_ind_account_no,
oldaccounteo.old_ind_account_name,
transactioncodeeo.forex_type_flag,
transactioncodeeo.forex_type,
glaccounteo.gl_account_type AS classification_flag,
bankcodeeo.member_code,
oldaccounteo.category_code,
glaccounteo.normal_position,
transactioncodeeo.source_account_flag,
transactioncodeeo.usage_forex,
bankcodeeo.member_type,
TRANSACTIONCODEEO.CURRENCY_TYPE
FROM bank_codes bankcodeeo
INNER JOIN old_accounts oldaccounteo
ON bankcodeeo.account_no = oldaccounteo.old_ind_account_no
AND oldaccounteo.approval_status = '2'
AND oldaccounteo.activation_status = '1'
INNER JOIN gl_sl_accounts glsleo
ON glsleo.gl_account_no = oldaccounteo.gl_account_no
AND glsleo.sl_account_no = oldaccounteo.sl_account_no
AND glsleo.approval_status = '2'
AND glsleo.activation_status = '1'
INNER JOIN gl_accounts glaccounteo
ON glaccounteo.gl_account_no = glsleo.gl_account_no
AND glaccounteo.approval_status = '2'
AND glaccounteo.activation_status = '1'
INNER JOIN tc_gl tcgleo
ON tcgleo.gl_account_no = glaccounteo.gl_account_no
INNER JOIN transaction_codes transactioncodeeo
ON transactioncodeeo.transaction_code = tcgleo.transaction_code
AND transactioncodeeo.approval_status = '2'
AND transactioncodeeo.activation_status = '1'
WHERE bankcodeeo.approval_status = '2'
AND bankcodeeo.activation_status = '1');
COMMIT;
END;
/
當我更新表BANK_CODE
,我得到了一個錯誤:
ORA-01732: data manipulation operation not legal on this view
ORA-06512: at "SP_UPDATE_MV_BANK_CODES", line 6
ORA-06512: at "MV_BANK_CODE_UPDATE", line 3
ORA-04088: error during execution of trigger 'MV_BANK_CODE_UPDATE'
其次,我用DBMS_MVIEW.REFRESH
:
CREATE OR REPLACE TRIGGER MV_BANK_CODE_UPDATE_X
AFTER UPDATE OR INSERT OR DELETE OF APPROVAL_STATUS ON BANK_CODES
FOR EACH ROW
BEGIN
DBMS_MVIEW.REFRESH('MV_BANK_CODES');
END MV_BANK_CODE_UPDATE_X;
/
當我updat編輯表BANK_CODE
,我得到一個錯誤:
ORA-04092: cannot COMMIT in a trigger
ORA-06512: at "SYS.DBMS_SNAPSHOT", line 3014
ORA-06512: at "SYS.DBMS_SNAPSHOT", line 2994
ORA-06512: at "MV_BANK_CODE_UPDATE_X", line 3
ORA-04088: error during execution of trigger 'MV_BANK_CODE_UPDATE_X'
我該怎麼辦?
我找到了一個鏈接,其中賈斯汀洞穴精美回答的http:// stackoverflow.com/questions/13068366/how-to-refresh-materialized-view-using-trigger –