-
Notifications
You must be signed in to change notification settings - Fork 0
/
VIEW_MATERALIZADA ONDEMAND.sql
59 lines (51 loc) · 1.9 KB
/
VIEW_MATERALIZADA ONDEMAND.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
DBMS_SYNC_REFRESH
EXECUTE DBMS_SYNC_REFRESH.REGISTER_MVIEWS('MV1');
DBMS_MVIEW.REFRESH
DBMS_MVIEW.REFRESH('MVIEW_TGFNST', 'C', '', TRUE, FALSE, 0,0,0,
FALSE, FALSE);
CREATE MATERIALIZED VIEW product_sales_mv
PCTFREE 0 TABLESPACE demo
STORAGE (INITIAL 8M)
BUILD DEFERRED
REFRESH COMPLETE ON DEMAND
ENABLE QUERY REWRITE AS
SELECT p.prod_name, SUM(s.amount_sold) AS dollar_sales
FROM sales s, products p WHERE s.prod_id = p.prod_id
GROUP BY p.prod_name;
CREATE MATERIALIZED VIEW unionall_inside_view_mv
REFRESH FAST ON DEMAND AS
SELECT * FROM view_with_unionall;
select *
from (table(TGFNST_PKG.FCN_TGFNST($P{CODEMP},$P{DTINICIAL} ,$P{DTFINAL}))) O
WHERE O.VLRSUBSTSAI >0
order by O.NUNOTA,O.NUMNOTA,O.CODPARC
CREATE MATERIALIZED VIEW MVIEW_TGFNST
BUILD DEFERRED
REFRESH COMPLETE ON DEMAND AS
(select *
from (table(TGFNST_PKG.FCN_TGFNST(1,TRUNC(SYSDATE,'MM') ,LAST_DAY(TRUNC(SYSDATE,'MM'))))) O
WHERE O.VLRSUBSTSAI >0
UNION ALL
select *
from (table(TGFNST_PKG.FCN_TGFNST(1,ADD_MONTHS(TRUNC(SYSDATE,'MM'),-1) ,LAST_DAY(ADD_MONTHS(TRUNC(SYSDATE,'MM'),-1)) ))) O
WHERE O.VLRSUBSTSAI >0
UNION ALL
select *
from (table(TGFNST_PKG.FCN_TGFNST(1,ADD_MONTHS(TRUNC(SYSDATE,'MM'),-2) ,LAST_DAY(ADD_MONTHS(TRUNC(SYSDATE,'MM'),-2)) ))) O
WHERE O.VLRSUBSTSAI >0
UNION ALL
select *
from (table(TGFNST_PKG.FCN_TGFNST(2,TRUNC(SYSDATE,'MM') ,LAST_DAY(TRUNC(SYSDATE,'MM'))))) O
WHERE O.VLRSUBSTSAI >0
UNION ALL
select *
from (table(TGFNST_PKG.FCN_TGFNST(2,ADD_MONTHS(TRUNC(SYSDATE,'MM'),-1) ,LAST_DAY(ADD_MONTHS(TRUNC(SYSDATE,'MM'),-1)) ))) O
WHERE O.VLRSUBSTSAI >0
UNION ALL
select *
from (table(TGFNST_PKG.FCN_TGFNST(2,ADD_MONTHS(TRUNC(SYSDATE,'MM'),-2) ,LAST_DAY(ADD_MONTHS(TRUNC(SYSDATE,'MM'),-2)) ))) O
WHERE O.VLRSUBSTSAI >0)
SELECT MVIEW_NAME, STALENESS, LAST_REFRESH_TYPE, COMPILE_STATE,LAST_REFRESH_DATE
FROM USER_MVIEWS ORDER BY MVIEW_NAME;
DBMS_MVIEW.REFRESH('MVIEW_TGFNST', 'C', '', TRUE, FALSE, 0,0,0,
TRUE, FALSE);