简体   繁体   中英

Need to update an Oracle view, but the base table doesn't exist

I'm trying to make an extremely minor change to a view on an oracle database, but what's confusing me is that the base table/view for the view I want to change doesn't seem to exist.

First I did this:

select text from all_views where view_name='(view name)';

and got the view text, which of course was something like this:

SELECT (fields) FROM (table)

Trying to run this query on its own returns an error saying that this table or view does not exist. Searching through the lists of table names and views on the all_ tables returns nothing. Creating a new view with the same source select statement tells me I can't make it because the table or view doesn't exist. Now, this is a production database, so this should work because I can use the existing view just fine. I don't have much experience with oracle databases, so I'm probably missing something here.

I'm betting the view is in another schema. Does this return the same as your first query:

select text from all_views where view_name='(view name)' and owner = user;

If that returns no rows, then you need to find the view's owner:

select owner from all_views where view_name = '(view_name)';

And change your SQL to

select (fields) from (view_owner).(table);

You can create a view even if there doesn't exist base table by "FORCE" option("NO FORCE" is

the default) by this way:

CREATE FORCE VIEW test_view AS

SELECT c1, c2 FROM test_table; -- table, which does not exist yet.

Since we did not use the FORCE option, the view was not created.However, trying to access the

view gives an error, because the table TEST_TABLE does not exist yet.

By using "FORCE" we can also create a view by dual table(default table for oracle).

1-Example:create force view v1 as select a,b,c from dual;

Warning:view created with compilation error.

2-Example:create force view v2 as select *from dual;

Answer:view created.

Wow, nevermind. They weren't even asking me to do this. I missed that part in the original email.

您应该使用force关键字。

create force view my_view as elect column1 from table_test -- table is not exists here..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM