0

我使用 SQL Anywhere 11。

我有以下看法:

CREATE MATERIALIZED VIEW "DBA"."PointsAcc"( /* view_column_name, ... */ )
IN "SYSTEM" AS
select sum(PL.Points) AS Sum, DP.UserUID, COUNT(*) AS cnt
FROM Points DP
KEY JOIN PointLine PL
KEY JOIN PointHead PH
GROUP BY DP.UserUID

我在 PointLine 中有一个触发器,应该从此视图中选择总和:

CREATE TRIGGER "WorkOnPoints" AFTER INSERT, DELETE
ORDER 1 ON "DBA"."Points"
REFERENCING OLD AS oldrow NEW AS newrow 
FOR EACH ROW
BEGIN
    declare @points integer;
    set @points = (isnull((select isnull(Sum, 0)) FROM PointsAcc where UserUID = newrow.UserUID), 0)) 
END;

@points 变量现在包含插入或删除行之前的总和。如何从触发器中的视图中获取更新的总和?

4

1 回答 1

1

这取决于您当前使用的 SQLA 版本。

如果您没有创建“立即刷新视图”选项,则必须调用

REFRESH MATERIALIZED VIEW view-list

有关更多详细信息,请查看这些链接

http://dcx.sybase.com/index.html#1201/en/dbreference/alter-materialized-view-statement.html

http://dcx.sybase.com/1201/en/dbreference/refresh-materialized-view-statement.html

于 2012-05-23T15:37:17.967 回答