如何在 sql Oracle 12c 中使用 ALTER VIEW 在视图中添加列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42722312/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add column in a view using ALTER VIEW in sql Oracle 12c
提问by user3346439
INITIAL VIEW CREATED
初始视图已创建
create or replace view concert_view
as
select concert.concert_id
from concert, event
where concert.concert_id=event.concert_id;
WHEN I TRIED TO ADD COLUMNS USING
当我尝试使用添加列时
alter view concert_view as
select
cname,edate
from concert,event
where concert.concert_id=event.concert_id;
I HAVE AN ERROR MESSAGE
我有一条错误信息
alter view concert_view as
*
ERROR at line 1:
ORA-00922: missing or invalid option
将 concert_view 更改为
* 第 1 行的错误:ORA-00922:缺少或无效的选项
回答by BriteSponge
ALTER VIEW is not used in this way. The only options for altering a view are to add/drop/modify constraints or to RECOMPILE the view.
ALTER VIEW 不以这种方式使用。更改视图的唯一选项是添加/删除/修改约束或重新编译视图。
If you want to add columns then just run the CREATE OR REPLACE VIEW statement again with a different select.
如果要添加列,则只需使用不同的选择再次运行 CREATE OR REPLACE VIEW 语句。
回答by Nitin Bohra
A View is basically only a SELECT -statement. If you want to add another column to your view, just change the statement on which it is based. And recreate a view.
视图基本上只是一个 SELECT 语句。如果您想在视图中添加另一列,只需更改它所基于的语句。并重新创建视图。