【发布时间】:2021-07-16 20:54:14
【问题描述】:
我们制作了一个名为“Complaint_view”的物化视图。每当在“投诉”表上执行插入、删除或更新时,我们都希望刷新此视图。我们使用以下代码来制作视图...
create materialized view complaint_view
build immediate
refresh complete
on demand
as
select t1.Complaint_ID,Status,C_TimeStamp,Description,House_No,Owner_name,Staff_ID,Staff_name from
(select Complaint_ID,Status,C_TimeStamp,Description,Complaint.House_No,Person.Name as Owner_name
from Complaint
join House
on Complaint.House_No = House.House_No
join Person
on House.Owner_ID = Person.Person_Id) t1
left outer join
(select Complaint_ID,Complaint.Staff_ID, Person.Name as Staff_name
from Complaint
join Person
on Complaint.Staff_ID = Person.Person_ID) t2
on t1.Complaint_ID = t2.Complaint_ID;
select 语句是有目的的,它也使用其他表。
我为它做了以下触发器
create or replace trigger refresh_comp_view
after insert or update or delete on Complaint
DECLARE
PRAGMA AUTONOMOUS_TRANSACTION;
begin
dbms_mview.refresh(LIST=>'complaint_view');
commit;
end refresh_comp_view;
当我更新投诉表时,视图会更新,但之前的更新会被存储。
例如,如果我首先将列更新为“123”,然后再次更新为“1234567”,那么在物化视图中,我将得到“123”而不是“1234567”。
这里有什么问题?为什么要在物化视图中更新以前的值?
【问题讨论】:
-
会不会是因为你的触发器是
BEFORE INSERT OR ...触发器?在执行实际语句之前触发该触发器。尝试将其更改为AFTER INSERT OR ... -
另外,触发器中不需要提交,但我会重新考虑我的架构......这可能会导致严重的性能问题。
-
after和before发生了同样的事情。
标签: sql database oracle plsql oracle11g