Oracle:修改 varchar 列大小后重新创建数据库视图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3667016/
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
Oracle: Recreate database view after modifying varchar column size
提问by user169743
I've made some changes to columns in a database table (increasing the size of varchar), however I need to have the view of the table refreshed to pick up this change. In SQL server 2005 I would use the script to -> alter to recreate the script for the view. I'm trying to figure out what the Oracle SQL command would be to rebuild the view to display the change of the column?
我对数据库表中的列进行了一些更改(增加了 varchar 的大小),但是我需要刷新表的视图以获取此更改。在 SQL Server 2005 中,我将使用脚本 to -> alter 为视图重新创建脚本。我想弄清楚 Oracle SQL 命令是什么来重建视图以显示列的更改?
回答by Alex Poole
Unless your view is explicitly restricting the size of the column, it will pick up the change automatically. It may have been invalidated by the table change but would be automatically recompiled when first used; or can be manually recompiled with alter view <view name> compile
.
除非您的视图明确限制列的大小,否则它会自动获取更改。它可能因表更改而失效,但在第一次使用时会自动重新编译;或者可以手动重新编译alter view <view name> compile
。
回答by Martin Mares
If you do so:
如果你这样做:
create table sample_table(text varchar2(10));
insert into sample_table (text) values('text...');
create view sample_view as select * from sample_table;
select * from sample_view;
alter table sample_table modify text varchar2(200);
You do not do anything to promote this change in view in Oracle database.
您没有做任何事情来促进 Oracle 数据库中的这种更改。
Or you can use "ALTER VIEW sample_view COMPILE" (how wrote @AlexPole or @devio). Oracle do this automatically when you firstly use select on sample_view after alter table.
或者您可以使用“ALTER VIEW sample_view COMPILE”(@AlexPole 或@devio 是如何写的)。当您在更改表之后第一次在 sample_view 上使用 select 时,Oracle 会自动执行此操作。
回答by devio
Try
尝试
ALTER VIEW MyView COMPILE;