简体   繁体   English

需要更新Oracle视图,但基本表不存在

[英]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. 我正在尝试对oracle数据库上的视图进行非常小的更改,但令我感到困惑的是,我要更改的视图的基本表/视图似乎不存在。

First I did this: 首先,我这样做:

select text from all_views where view_name='(view name)'; 从all_views中选择文本,其中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. 搜索表名列表和all_表上的视图将不返回任何内容。 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. 使用相同的源select语句创建一个新视图会告诉我,因为该表或视图不存在,所以无法创建该视图。 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. 我对oracle数据库没有太多经验,因此我可能在这里缺少一些东西。

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 并将您的SQL更改为

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 即使没有基表,也可以通过“ FORCE”选项创建视图(“ NO FORCE”为

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 由于我们未使用FORCE选项,因此未创建视图。但是,尝试访问

view gives an error, because the table TEST_TABLE does not exist yet. 视图给出错误,因为表TEST_TABLE还不存在。

By using "FORCE" we can also create a view by dual table(default table for oracle). 通过使用“ FORCE”,我们还可以通过双表(oracle的默认表)创建视图。

1-Example:create force view v1 as select a,b,c from dual; 1-示例:创建力视图v1,从对偶中选择a,b,c;

Warning:view created with compilation error. 警告:创建视图时出现编译错误。

2-Example:create force view v2 as select *from dual; 2-示例:创建强制视图v2作为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..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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