0
我需要在表上创建视图,并且不希望每次更改表结构时都要更改视图。有没有这种可能性?任何指针赞赏这一点。Oracle视图不会影响基础表结构更改
我需要在表上创建视图,并且不希望每次更改表结构时都要更改视图。有没有这种可能性?任何指针赞赏这一点。Oracle视图不会影响基础表结构更改
如果您不想指定表格中的所有字段,那么即使我不喜欢这样的解决方案,但您总是必须在表格后重建视图,您也可以定义一个类似select *
的视图改变。 例如:
SQL> create table yourTable (a number, b number);
Table created.
SQL> insert into yourTable values (1, 2);
1 row created.
SQL> insert into yourTable values (10, 20);
1 row created.
SQL> create or replace view yourView as select * from yourTable;
View created.
视图正常工作:
SQL> select * from yourView;
A B
---------- ----------
1 2
10 20
如果添加列,视图不会表现出来:
SQL> alter table yourTable add (c number);
Table altered.
SQL> select * from yourView;
A B
---------- ----------
1 2
10 20
您需要重建视图有新栏目:
SQL> create or replace view yourView as select * from yourTable;
View created.
SQL> select * from yourView;
A B C
---------- ---------- ----------
1 2
10 20
如果放置一列,您的视图将变为无效,并且您需要重建它:
SQL> alter table yourTable drop column c;
Table altered.
SQL> select * from yourView;
select * from yourView
*
ERROR at line 1:
ORA-04063: view "ALEK.YOURVIEW" has errors
SQL> create or replace view yourView as select * from yourTable;
View created.
SQL> select * from yourView;
A B
---------- ----------
1 2
10 20