我是在Oracle中编写存储过程的新手。我想将物化视图日志的创建脚本保存到临时表。删除这些物化视图日志,然后使用临时表中存储的脚本重新创建它们,然后删除该表。 这是我到目前为止所做的,还有很长的路要走。
create or replace PROCEDURE procPrintOutput
IS
l_stmt VARCHAR2(512) := '';
--create_table_stmt VARCHAR2(512) := 'create global temporary table temp(matViewLogQuery VARCHAR2(4000))';
select_stmt VARCHAR2(512) := 'SELECT * from temp';
BEGIN
DBMS_OUTPUT.PUT_LINE('1');
DECLARE
CURSOR LIST_OF_MVL IS SELECT * FROM USER_BASE_TABLE_MVIEWS;
BEGIN
DBMS_OUTPUT.PUT_LINE('2');
FOR TEST IN LIST_OF_MVL
LOOP
BEGIN
DBMS_OUTPUT.PUT_LINE('owner : ' || TEST.OWNER || ' - name : ' || TEST.MASTER);
l_stmt := 'insert into temp SELECT SYS.DBMS_METADATA.get_dependent_ddl (''MATERIALIZED_VIEW_LOG'', ''|| TEST.MASTER||'', ''|| TEST.OWNER ||'') from dual';
EXECUTE IMMEDIATE (l_stmt);
END;
END LOOP;
END;
DBMS_OUTPUT.PUT_LINE('Done!');
END;
运行此错误时我得到的错误是
ORA-31608: specified object of type MATERIALIZED_VIEW_LOG not found
ORA-06512: at "SYS.DBMS_METADATA", line 5088
ORA-06512: at "SYS.DBMS_METADATA", line 7681
ORA-06512: at line 1
ORA-06512: at "XXX.PROCPRINTOUTPUT", line 25
ORA-06512: at line 2
有什么想法吗?
答案 0 :(得分:0)
问题在于逃避。这是如何解决的:
l_stmt := 'insert into temp SELECT SYS.DBMS_METADATA.get_dependent_ddl (''MATERIALIZED_VIEW_LOG'', '''||TEST.MASTER||''', '''||TEST.OWNER||''') from dual';
由于