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