关于物化视图疑问(32天)

--初始化操作,

创建两个用户一个,testo,一个test.

在testo上创建表,test上创建物化视图。

SQL> create user testo identified by testo;
User created.
SQL> create user test identified by test;
User created.
SQL> grant connect,resource to testo,test;
Grant succeeded.
SQL> grant create materialized view to test;
Grant succeeded.
SQL> grant create role to testo;
Grant succeeded.
SQL> conn testo/testo;     
Connected.
SQL> create table mv as select *from all_objects where object_id is not null and rownum<50;
Table created.
SQL> create role t1;
Role created.
SQL> grant select on testo.mv to t1;
Grant succeeded.
SQL> grant t1 to test;
Grant succeeded.
SQL> conn test/test  --连接到test用户,准备创建物化视图。
Connected.
SQL> create materialized view test_mv as select *from testo.mv;--尝试默认的选项,可以成功创建。
Materialized view created.
SQL> drop materialized view test_mv;
Materialized view dropped.
SQL> create materialized view test_mv refresh force on demand with rowid using default local rollback segment disable query rewrite as select *from testo.mv;  -尝试指定选项创建,也可以成功创建。
Materialized view created.
SQL> drop materialized view test_mv;
Materialized view dropped.

问题 1:

SQL> conn system/unix11   --连接到system
Connected.
SQL> create materialized view test.test_mv refresh force on demand with rowid using default local rollback segment disable query rewrite as select *from testo.mv;
create materialized view test.test_mv refresh force on demand with rowid using default local rollback segment disable query rewrite as select *from testo.mv
                                                                                                                                                          *
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> desc testo.mv
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 OWNER                                     NOT NULL VARCHAR2(30)
 OBJECT_NAME                               NOT NULL VARCHAR2(30)
 SUBOBJECT_NAME                                     VARCHAR2(30)
 OBJECT_ID                                 NOT NULL NUMBER
 DATA_OBJECT_ID                                     NUMBER
 OBJECT_TYPE                                        VARCHAR2(19)
 CREATED                                   NOT NULL DATE
 LAST_DDL_TIME                             NOT NULL DATE
 TIMESTAMP                                          VARCHAR2(19)
 STATUS                                             VARCHAR2(7)
 TEMPORARY                                          VARCHAR2(1)
 GENERATED                                          VARCHAR2(1)
 SECONDARY                                          VARCHAR2(1)
 NAMESPACE                                 NOT NULL NUMBER
 EDITION_NAME                                       VARCHAR2(30)
SQL> 

问题 2:

SQL> grant select on testo.mv to public; --赋予public权限
Grant succeeded.
SQL> create materialized view test.test_mv refresh force on demand with rowid using default local rollback segment disable query rewrite as select *from testo.mv
  2  ;
create materialized view test.test_mv refresh force on demand with rowid using default local rollback segment disable query rewrite as select *from testo.mv
                                                                                                                                                          *
ERROR at line 1:
ORA-01031: insufficient privileges

排除role的影响

SQL> grant select on testo.mv to test;
Grant succeeded.
SQL> create materialized view test.test_mv refresh force on demand with rowid using default local rollback segment disable query rewrite as select *from testo.mv
  2  ;
create materialized view test.test_mv refresh force on demand with rowid using default local rollback segment disable query rewrite as select *from testo.mv
                                                                                                                                                          *
ERROR at line 1:
ORA-01031: insufficient privileges
SQL> revoke select on testo.mv from test;
Revoke succeeded.

问题 3(已解决)

SQL> select dbms_metadata.get_ddl('MATERIALIZED VIEW','MV','TEST') from dual;
ERROR:
ORA-31600: invalid input value MATERIALIZED VIEW for parameter OBJECT_TYPE in
function GET_DDL
ORA-06512: at "SYS.DBMS_METADATA", line 3773
ORA-06512: at "SYS.DBMS_METADATA", line 3828
ORA-06512: at "SYS.DBMS_METADATA", line 5678
ORA-06512: at line 1

生成报错,

确认了下,应该得改成MATERIALIZED_VIEW

SQL> select dbms_metadata.get_ddl('MATERIALIZED_VIEW','TEST_MV','TEST')from dual;
  CREATE MATERIALIZED VIEW "TEST"."TEST_MV" ("OWNER", "OBJECT_NAME", "SUBOBJECT_
NAME", "OBJECT_ID", "DATA_OBJECT_ID", "OBJECT_TYPE", "CREATED", "LAST_DDL_TIME",
 "TIMESTAMP", "STATUS", "TEMPORARY", "GENERATED", "SECONDARY", "NAMESPACE", "EDI
TION_NAME")
  ORGANIZATION HEAP PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOG
GING........

就可以了。

原文发布于微信公众号 - 杨建荣的学习笔记(jianrong-notes)

原文发表时间:2014-04-04

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏乐沙弥的世界

使用exchange方式切换普通表到分区表

      随着数据库数据量的不断增长,有些表需要由普通的堆表转换为分区表的模式。有几种不同的方法来对此进行操作,诸如导出表数据,然后创建分区表再导入数据到分区...

671
来自专栏me的随笔

T-SQL基础(五)之增删改

在前面的文章中对T-SQL的查询做了基本总结,接下来我们看下SQL中的另外一个常用操作——数据的修改。

792
来自专栏沃趣科技

SQL优化案例-分区索引之无前缀索引(六)

无前缀索引:分区索引不包含分区字段就叫无前缀索引,那么什么时候用无前缀索引和前缀索引呢?

1122
来自专栏数据库新发现

Oracle9i新特性-使用DBMS_METADATA包获得对象DDL语句

从Oracle9i开始Oracle提供了一个新的系统包DBMS_METADATA,可以用于提取对象创建的DDL语句。

1142
来自专栏乐沙弥的世界

Oracle 性能相关常用脚本(SQL)

在缺乏的可视化工具来监控数据库性能的情形下,常用的脚本就派上用场了,下面提供几个关于Oracle性能相关的脚本供大家参考。以下脚本均在Oracle 10g测试通...

1012
来自专栏自由而无用的灵魂的碎碎念

oracle 10g 手动创建scott(tiger) schema

转自:http://cnhtm.itpub.net/post/39970/496967

1053
来自专栏杨建荣的学习笔记

mysql常用命令

这几天学习了一下mysql,对于mysql的命令总结如下,发现很多方面和oracle还是差别挺大的。 # mysql -uroot -p Enter passw...

3786
来自专栏程序员宝库

Mysql - JOIN 详解

一个完整的SQL语句中会被拆分成多个子句,子句的执行过程中会产生虚拟表(vt),但是结果只返回最后一张虚拟表。从这个思路出发,我们试着理解一下JOIN查询的执行...

2093
来自专栏Aloys的开发之路

DB2常用语句

CREATE TABLE STAFF_BAK LIKE STAFF; INSERT INTO STAFF_BAK SELECT * FROM STAFF; S...

1905
来自专栏WindCoder

个人常用语句笔记-SQL

643

扫码关注云+社区