关于物化视图疑问(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 条评论
登录 后参与评论

相关文章

来自专栏Aloys的开发之路

DB2常用语句

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

1795
来自专栏跟着阿笨一起玩NET

(3)合并列值与分拆列值

在SQL中分拆列值和合并列值老生常谈了,从网上搜刮了一下并记录下来,以便不时之需 :)

591
来自专栏互联网研发闲思录

mybaties 的一些点

resultMap resutType mybaties缓存 待续 mybaties对应关系是bean和数据库字段的对应。 1、mybaties 的返回值是对象...

1688
来自专栏landv

SQL得到任意一个存储过程的参数列表sp_procedure_params_rowset

1422
来自专栏数据库新发现

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

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

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

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

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

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

传输表空间及问题处理(84天)

今天试验表空间传输,从一个库PROD 传输表空间到repos 假定表employees 在tbs4表空间里 SQL> select table_name,tab...

3437
来自专栏landv

SQL得到任意一个存储过程的参数列表sp_procedure_params_rowset

784
来自专栏海说

Java应用中常见的JDBC连接字符串(SQLite、MySQL、Oracle、Sybase、SQLServer、DB2)

Java应用中常见的JDBC连接字符串 Java应用中连接数据库是不可或缺的,于是便整理一些可能用到的JDBC的jar包及其相匹配的URL,以备日后查阅。 1)...

2350
来自专栏数据库新发现

Oracle10gR2 New Feature:V$SESSION change tracking

作者:eygle 出处:http://www.eygle.com/blog 日期:September 15, 2005 本文链接:http://www.eyg...

362

扫码关注云+社区