SQL> create table test (col number(3));
Table created.
SQL> insert into test values (123);
1 row created.
SQL> create or replace view v_test as select * From test;
View created.
SQL> select * from v_test;
COL
----------
123
SQL> desc v_test
Name Null? Type
----------------------------------------- -------- ----------------------------
COL NUMBER(3)
SQL> alter table test modify col number(8);
Table altered.
SQL> select * from v_test;
COL
----------
123
SQL> desc v_test
Name Null? Type
----------------------------------------- -------- ----------------------------
COL NUMBER(8)
SQL>
SQL> create table test (id number, col number(3));
Table created.
SQL> insert into test values (1, 123);
1 row created.
SQL> create or replace view v_test as select * from test;
View created.
SQL> select * From v_test;
ID COL
---------- ----------
1 123
SQL> desc v_test
Name Null? Type
----------------------------------------- -------- ----------------------------
ID NUMBER
COL NUMBER(3) --> number (3)
删除该列并将其放回,修改数据类型:
SQL> alter table test drop column col;
Table altered.
SQL> alter table test add col number(8);
Table altered.
检查其数据类型:就像我说的,它会自动反映出来:
SQL> desc v_test
Name Null? Type
----------------------------------------- -------- ----------------------------
ID NUMBER
COL NUMBER(8) --> number (8)
SQL> select * from v_test;
ID COL
---------- ----------
1 --> COL is empty, though
SQL>
1条答案
按热度按时间hwamh0ep1#
在这种情况下,不需要删除列;你可以直接修改它
即使你通过删除一个列(这可能是一个坏主意,因为你丢失了存储在其中的数据),视图也应该自动反映数据类型的变化:
删除该列并将其放回,修改数据类型:
检查其数据类型:就像我说的,它会自动反映出来: