尝试在我的“刷新”中删除并重新创建索引。存储过程,但收到错误

时间:2018-03-09 18:53:09

标签: sql oracle

我正在尝试使用以下存储过程删除/重新创建索引并每天刷新MV。但是我收到了编译错误。此外,对于大多数物化视图刷新作业,(可能不在主题上),还有什么可以被认为是“良好实践”和#39;包括?提前谢谢!

create or replace PROCEDURE "DAILY_MV_REFRESH" AS
BEGIN
  --Drop Index(es)
drop bitmap index mv_test_id;
  --Refresh the Materialized View(s)
dbms_mview.refresh('MV_TEST');
  --Recreate Index(es)
create bitmap index mv_test_id on mv_test(test_id);
END;

1 个答案:

答案 0 :(得分:1)

You can't execute DDL directly in a PL/SQL procedure; it has to be in an execute immediate statement.

create or replace PROCEDURE "DAILY_MV_REFRESH" AS
BEGIN
  --Drop Index(es)
  execute immediate 'drop bitmap index mv_test_id';
  --Refresh the Materialized View(s)
  dbms_mview.refresh('MV_TEST');
  --Recreate Index(es)
  execute immediate 'create bitmap index mv_test_id on mv_test(test_id)';
END;
/