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

相关文章

来自专栏数据库新发现

关于shared pool的深入探讨(五)

http://www.eygle.com/internal/shared_pool-5.htm

542
来自专栏个人分享

hiveql笔记(一)

create table if not exists mydb.employees{

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

浅谈exp/imp(上) (r5笔记第81天)

作为DBA,经常需要在不同数据库环境间做数据的导入导出,exp/imp就是这样的轻便快捷的客户端工具,可以很方便的在不同数据库之间转移数据对象,即使数据库位于不...

2568
来自专栏简单聊聊Spark

Hive基本操作

9.在hive中创建一张表的时候,同时为某一个字段指定为partition,这里其实还是创建了一个有三个字段的表,只是username被当作partition掉...

762
来自专栏Albert陈凯

2018-07-24 MERGE Insert not working

https://www.sqlservercentral.com/Forums/1551626/MERGE-Insert-not-working

712
来自专栏乐沙弥的世界

收缩Oracle数据文件

      最近有网友提到收缩Oracle数据文件的问题,这是DBA经常碰到的一个常见问题。通常我们需要收缩相应的数据文件以减少来自磁盘空间的压力以及提高数据库...

552
来自专栏小狼的世界

MYSQL在众多表中查询表名和字段名

SELECT table_name, column_name from information_schema.columns WHERE column_name...

883
来自专栏王硕

原 Postgresql-XL安装部署

47116
来自专栏数据库

oracle常用命令大全

一、Oracle数据库实例、用户、目录及session会话查看: 1、ORACLE SID查看设置 查看SID、用户名 $ env|grep SID 、sele...

2857
来自专栏代码小睿

Medoo个人修改版

  Medoo是一款轻量级的php数据库操作类,下面不会介绍Medoo的使用方法,想学习Medoo请前往官网自学:http://medoo.in/   在接触M...

2007

扫描关注云+社区