DBMS_MVIEW提供了全部物化视图刷新、指定物化视图刷新、依赖于指定对象的物化视图刷新以及获取依赖于指定对象的物化视图的能力。

DBMS_MVIEW 子程序总览

子程序

说明

REFRESH_ALL_MVIEWS Procedure

刷新全部物化视图。

REFRESH Procedure

刷新指定物化视图。

REFRESH_DEPENDENT Procedure

刷新依赖于指定对象的物化视图。

GET_MV_DEPENDENT Procedure

获取依赖于指定对象的物化视图。

REFRESH_ALL_MVIEWS

该存储过程用于刷新全部物化视图。

语法

PROCEDURE REFRESH_ALL_MVIEWS (
    number_of_failures     OUT   BINARY_INTEGER,
    method                 IN    VARCHAR2         := NULL,
    rollback_seg           IN    VARCHAR2         := NULL,
    refresh_after_errors   IN    BOOLEAN          := FALSE,
    atomic_refresh         IN    BOOLEAN          := TRUE,
    out_of_place           IN    BOOLEAN          := FALSE);

参数说明

参数

说明

number_of_failures

物化视图刷新失败数量。

method

(可选参数)物化视图刷新方法。取值如下:

  • C或c:表示complete refresh

  • A或a:表示always refresh

说明

C或c、A或a的刷新方式是等价的,均表示always refresh。

rollback_seg

(可选参数)指定物化视图刷新时的回滚段。兼容性提供参数。

refresh_after_errors

(可选参数)物化视图刷新过程中产生错误后是否会继续刷新。兼容性提供参数。

atomic_refresh

(可选参数)是否为原子性刷新。兼容性提供参数。

out_of_place

(可选参数)兼容性提供参数。

示例

该示例刷新了当前数据库中的全部的物化视图。

CREATE TABLE test(a int, b int);

INSERT INTO test VALUES (1, 2);
CREATE MATERIALIZED VIEW mv0 AS SELECT a, b FROM test;

INSERT INTO test VALUES (2, 3);

SELECT * FROM mv0 ORDER BY 1, 2;
 a | b
---+---
 1 | 2
(1 row)

DECLARE
    a BINARY_INTEGER;
BEGIN
    DBMS_MVIEW.REFRESH_ALL_MVIEWS(a);
    -- The num of refresh failures is:0
    DBMS_OUTPUT.PUT_LINE('The num of refresh failures is:' || a);
END;

SELECT * FROM mv0 ORDER BY 1, 2;
 a | b
---+---
 1 | 2
 2 | 3
(2 rows)

REFRESH

该存储过程用于刷新指定的物化视图。

语法

PROCEDURE REFRESH (
    list                   IN     VARCHAR2,
    method                 IN     VARCHAR2       := NULL,
    rollback_seg           IN     VARCHAR2       := NULL,
    push_deferred_rpc      IN     BOOLEAN        := true,
    refresh_after_errors   IN     BOOLEAN        := false,
    purge_option           IN     BINARY_INTEGER := 1,
    parallelism            IN     BINARY_INTEGER := 0,
    heap_size              IN     BINARY_INTEGER := 0,
    atomic_refresh         IN     BOOLEAN        := true,
    nested                 IN     BOOLEAN        := false,
    out_of_place           IN     BOOLEAN        := false,
    skip_ext_data          IN     BOOLEAN        := false);

PROCEDURE REFRESH (
    tab                    IN     DBMS_UTILITY.UNCL_ARRAY,
    method                 IN     VARCHAR2       := NULL,
    rollback_seg           IN     VARCHAR2       := NULL,
    push_deferred_rpc      IN     BOOLEAN        := true,
    refresh_after_errors   IN     BOOLEAN        := false,
    purge_option           IN     BINARY_INTEGER := 1,
    parallelism            IN     BINARY_INTEGER := 0,
    heap_size              IN     BINARY_INTEGER := 0,
    atomic_refresh         IN     BOOLEAN        := true,
    nested                 IN     BOOLEAN        := false,
    out_of_place           IN     BOOLEAN        := false,
    skip_ext_data          IN     BOOLEAN        := false);

参数说明

参数

说明

list或者tab

需要刷新的物化视图列表。

method

(可选参数)物化视图刷新方法。取值如下:

  • C或c:表示complete refresh

  • A或a:表示always refresh

说明

C或c、A或a的刷新方式是等价的,均表示always refresh。

rollback_seg

(可选参数)指定物化视图刷新时的回滚段。兼容性提供参数。

push_deferred_rpc

(可选参数)仅用于可更新物化视图,是否将物化视图的修改推送到关联的主表或主物化视图。兼容性提供参数。

refresh_after_errors

(可选参数)物化视图刷新过程中产生错误后是否会继续刷新。兼容性提供参数。

purge_option

(可选参数)兼容性提供参数。

parallelism

(可选参数)兼容性提供参数。

heap_size

(可选参数)兼容性提供参数。

atomic_refresh

(可选参数)兼容性提供参数。

nested

(可选参数)兼容性提供参数。

out_of_place

(可选参数)兼容性提供参数。

skip_ext_data

(可选参数)兼容性提供参数。

示例

该示例刷新了指定的物化视图。

CREATE TABLE test(a int, b int);

INSERT INTO test VALUES (1, 2);
CREATE MATERIALIZED VIEW mv0 AS SELECT a, b FROM test;

INSERT INTO test VALUES (2, 3);

SELECT * FROM mv0 ORDER BY 1, 2;
 a | b
---+---
 1 | 2
(1 row)

DECLARE
    la DBMS_UTILITY.UNCL_ARRAY;
BEGIN
    la := DBMS_UTILITY.UNCL_ARRAY('mv0');
    DBMS_MVIEW.REFRESH(tab => la,
                       method => 'A',
                       rollback_seg => NULL,
                       push_deferred_rpc => true,
                       refresh_after_errors => false,
                       purge_option => 1,
                       nested => false,
                       out_of_place => true,
                       skip_ext_data => true);
END;

SELECT * FROM mv0 ORDER BY 1, 2;
 a | b
---+---
 1 | 2
 2 | 3
(2 rows)

REFRESH_DEPENDENT

该存储过程用于刷新依赖于指定对象的物化视图。

语法

PROCEDURE REFRESH_DEPENDENT (
    number_of_failures     OUT    BINARY_INTEGER,
    list                   IN     VARCHAR2,
    method                 IN     VARCHAR2    := NULL,
    rollback_seg           IN     VARCHAR2    := NULL,
    refresh_after_errors   IN     BOOLEAN     := false,
    atomic_refresh         IN     BOOLEAN     := true,
    nested                 IN     BOOLEAN     := false,
    out_of_place           IN     BOOLEAN     := false);

PROCEDURE REFRESH_DEPENDENT (
    number_of_failures     OUT    BINARY_INTEGER,
    tab                    IN     DBMS_UTILITY.UNCL_ARRAY,
    method                 IN     VARCHAR2    := NULL,
    rollback_seg           IN     VARCHAR2    := NULL,
    refresh_after_errors   IN     BOOLEAN     := false,
    atomic_refresh         IN     BOOLEAN     := true,
    nested                 IN     BOOLEAN     := false,
    out_of_place           IN     BOOLEAN     := false);

参数说明

参数

说明

number_of_failures

物化视图刷新失败数量。

list或者tab

需要刷新的物化视图依赖对象的列表。

method

(可选参数)物化视图刷新方法。取值如下:

  • C或c:表示complete refresh

  • A或a:表示always refresh

说明

C或c、A或a的刷新方式是等价的,均表示always refresh。

rollback_seg

(可选参数)指定物化视图刷新时的回滚段。兼容性提供参数。

refresh_after_errors

(可选参数)物化视图刷新过程中产生错误后是否会继续刷新。兼容性提供参数。

atomic_refresh

(可选参数)是否为原子性刷新。兼容性提供参数。

nested

(可选参数)兼容性提供参数。

out_of_place

(可选参数)兼容性提供参数。

示例

该示例刷新了所有依赖于指定对象的物化视图。

CREATE TABLE test(a int, b int);

INSERT INTO test VALUES (1, 2);
CREATE MATERIALIZED VIEW mv0 AS SELECT a, b FROM test;

INSERT INTO test VALUES (2, 3);

SELECT * FROM mv0 ORDER BY 1, 2;
 a | b
---+---
 1 | 2
(1 row)

DECLARE
    la  DBMS_UTILITY.UNCL_ARRAY;
    len INTEGER;
    nof BINARY_INTEGER;
BEGIN
    DBMS_UTILITY.COMMA_TO_TABLE('test', len, la);
    DBMS_MVIEW.REFRESH_DEPENDENT(number_of_failures => nof,
                                 tab => la,
                                 method => 'A',
                                 rollback_seg => NULL,
                                 refresh_after_errors => true,
                                 atomic_refresh => false,
                                 nested => false,
                                 out_of_place => true);
    -- The num of refresh failures is:0
    DBMS_OUTPUT.PUT_LINE('The num of refresh failures is:' || nof);
END;

SELECT * FROM mv0 ORDER BY 1, 2;
 a | b
---+---
 1 | 2
 2 | 3
(2 rows)

GET_MV_DEPENDENT

该存储过程用于获取依赖于指定对象的所有物化视图。

语法

PROCEDURE GET_MV_DEPENDENCIES (
    mvlist  IN   VARCHAR2,
    deplist OUT  VARCHAR2);

参数说明

参数

说明

mvlist

被物化视图依赖的对象列表。

deplist

所有依赖指定对象的物化视图列表。

示例

该示例获取依赖于指定对象的所有物化视图。

CREATE TABLE test(a int, b int);

CREATE MATERIALIZED VIEW mv0 AS SELECT a, b FROM test;
CREATE MATERIALIZED VIEW mv1 AS SELECT a, b FROM test;

DECLARE
    deplist VARCHAR2;
BEGIN
    DBMS_MVIEW.GET_MV_DEPENDENCIES('test', deplist);
    -- The dependencies are: "PUBLIC"."MV0", "PUBLIC"."MV1"
    DBMS_OUTPUT.PUT_LINE('The dependencies are: ' || deplist);
END;