Oracle物化视图创建报ORA-00942错误解决
在Oracle 10g的数据库中,将一个物化视图做了一个简单的条件子句修改,删除后重建,但是,就建不成功,报ORA-00942表或视图不存在
在Oracle 10g的数据库中,将一个物化视图做了一个简单的条件子句修改,删除后重建,但是,就建不成功,报ORA-00942表或视图不存在错误。
这个问题很奇怪,我首先想这会是一个bug吗?找了oracle的metalink,还真有类似bug记载,,但给出的解决方法不合适。于是去自己分析解决,然后发现一个坑接着一个坑啊。
好吧,我先介绍物化视图的创建语句,如下所示:
CREATE MATERIALIZED VIEW V_TABLENAME
REFRESH COMPLETE ON DEMAND
START WITH TO_DATE('28-05-2013 16:55:32', 'DD-MM-YYYY HH24:MI:SS') NEXT SYSDATE + 1
AS
SELECT WID AS WID, KCM as KCM, JXBH AS JXBH, KKNF AS KKNF, KKXQM AS KKXQM, XQ AS XQ, JS AS JS, ZS AS ZS, JSGH AS JSGH
FROM USR_GXSJ.V_TABLENAME@dblink_name
where
(KKNF = '2012' AND KKXQM = '1') OR (KKNF = '2012' AND KKXQM = '2');
ORA-00942: table or view does not exist
ORA-06512: at "SYS.DBMS_SNAPSHOT_UTL", line 960
ORA-06512: at line 1
在Oracle的metalink中,一个名为Create Materialized View Results in : Ora-942 [ID 364632.1] 文档是这样解释说它是一个bug。
Symptoms
Creating a Materialized view based on a view existing on the remote database results in the following errors:
ORA-00942: table or view does not exist
ORA-06512: at "SYS.DBMS_SNAPSHOT_UTL", line 1543
ORA-02063: preceding 2 lines from remote db
Significantly, the database link on the local side connects to user_c schema on the remote database.
On the remote database the configuration is :
user_a - table owner and Materialized View log owner;
user_b - has view on a table in user_a's schema : view1
user_c - has select privs on view in user_b's schema.
Changes
This issue occurs when the remote database is 10.2.
The problem did not occur with 9.2.X
Cause
This issue is addressed in : Bug 5015547.
Solution
In order to determine that it is this issue, create the database link to user_b schema.
This can serve as a workaround and confirmation that this is likely : Bug 5015547
Apply patch for Bug 5015547 to 10.2.0.X if it is thought you are experiencing this issue.
在这篇文档中,Oracle提出的解决方法,是将dblink修改成同一访问用户的,这里没去测试,因为这不符合我们的应用架构的规划。
没办法了,只好去自己去分析并在网上找找前人的案例。
首先,检查一下权限,看看显示授权行不行。将USR_GXSJ.V_TABLENAME的授权,不行,将USR_GXSJ.V_TABLENAME中的表再授权,也不行。
后来,在网上发现有一个人给出了这个问题的解决方法,将USR_GXSJ.V_TABLENAME@dblink_name这个数据源用select * from USR_GXSJ.V_TABLENAME@dblink_name做一次嵌套。
按照方法测试了一下,居然就可以了。
CREATE MATERIALIZED VIEW V_TABLENAME
REFRESH COMPLETE ON DEMAND
START WITH TO_DATE('28-05-2013 16:55:32', 'DD-MM-YYYY HH24:MI:SS') NEXT SYSDATE + 1
AS
SELECT WID AS WID, KCM as KCM, JXBH AS JXBH, KKNF AS KKNF, KKXQM AS KKXQM, XQ AS XQ, JS AS JS, ZS AS ZS, JSGH AS JSGH
FROM (select * from USR_GXSJ.V_TABLENAME@dblink_name)
where
(KKNF = '2012' AND KKXQM = '1') OR (KKNF = '2012' AND KKXQM = '2');
这里很悲剧,因为我们没搞懂为什么???
后来,发现这还不是最悲剧的,我们在添加工作记录时,顺手翻了以前的记录。
去年的记录
修改视图V_TABLENAME,报错
ora 00942 table or view does not exist
ora 06512 at SYS.DBMC_SNAPSHOT_UTL ,line 960
给了dba的权限,还是报一样的错误,想办法。。。。
。。。。。
开始说是bug,打了补丁后还是不对。
使用10046 event分析语句内部执行时遇到的具体错误
是再校验基础表的主键字段出错。
我们物化视图脚步中,没有指明是使用rowid还是primary key方式遍历数据。默认使用primary key。
根据记录提示,我们增加with rowid子句,创建成功。
原来,这个问题以前发生过,我们在一个坑里摔了两次,希望没第三次了。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.

Data Integration Simplification: AmazonRDSMySQL and Redshift's zero ETL integration Efficient data integration is at the heart of a data-driven organization. Traditional ETL (extract, convert, load) processes are complex and time-consuming, especially when integrating databases (such as AmazonRDSMySQL) with data warehouses (such as Redshift). However, AWS provides zero ETL integration solutions that have completely changed this situation, providing a simplified, near-real-time solution for data migration from RDSMySQL to Redshift. This article will dive into RDSMySQL zero ETL integration with Redshift, explaining how it works and the advantages it brings to data engineers and developers.

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

LaravelEloquent Model Retrieval: Easily obtaining database data EloquentORM provides a concise and easy-to-understand way to operate the database. This article will introduce various Eloquent model search techniques in detail to help you obtain data from the database efficiently. 1. Get all records. Use the all() method to get all records in the database table: useApp\Models\Post;$posts=Post::all(); This will return a collection. You can access data using foreach loop or other collection methods: foreach($postsas$post){echo$post->

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.
