如何修改table中一列的长度并同时查看?
how to modify the length of one column in table and view concurrently?
我在 oracle 数据库中有一个 table。我已将一列的长度从 VARCHAR2(50)
更改为 VARCHAR2(100)
。问题是列的长度在视图中没有改变。有什么建议吗?
我正在使用 ORACLE SQL Developer Version 4.0.2.15
。
更改 table 后,视图变为无效状态,您必须从视图中 recompile the view 或简单 select 使其再次有效并具有正确的定义.虽然视图无效,但它保留了旧定义,这就是您所看到的。
见下图
create table tab
(col1 varchar2(50));
create or replace view vtab as select col1 from tab;
select table_name, data_length from user_tab_columns where column_name = 'COL1';
TABLE_NAME DATA_LENGTH
---------- -----------
TAB 50
VTAB 50
alter table tab modify (col1 varchar2(100));
select table_name, data_length from user_tab_columns where column_name = 'COL1';
TABLE_NAME DATA_LENGTH
---------- -----------
TAB 100
VTAB 50
select status from user_objects where object_name = 'VTAB';
STATUS
-------
INVALID
视图无效,因此列长度错误。编译视图或简单问题select * from VTAB
alter view vtab compile;
select table_name, data_length from user_tab_columns where column_name = 'COL1';
TABLE_NAME DATA_LENGTH
---------- -----------
TAB 100
VTAB 100
我在 oracle 数据库中有一个 table。我已将一列的长度从 VARCHAR2(50)
更改为 VARCHAR2(100)
。问题是列的长度在视图中没有改变。有什么建议吗?
我正在使用 ORACLE SQL Developer Version 4.0.2.15
。
更改 table 后,视图变为无效状态,您必须从视图中 recompile the view 或简单 select 使其再次有效并具有正确的定义.虽然视图无效,但它保留了旧定义,这就是您所看到的。
见下图
create table tab
(col1 varchar2(50));
create or replace view vtab as select col1 from tab;
select table_name, data_length from user_tab_columns where column_name = 'COL1';
TABLE_NAME DATA_LENGTH
---------- -----------
TAB 50
VTAB 50
alter table tab modify (col1 varchar2(100));
select table_name, data_length from user_tab_columns where column_name = 'COL1';
TABLE_NAME DATA_LENGTH
---------- -----------
TAB 100
VTAB 50
select status from user_objects where object_name = 'VTAB';
STATUS
-------
INVALID
视图无效,因此列长度错误。编译视图或简单问题select * from VTAB
alter view vtab compile;
select table_name, data_length from user_tab_columns where column_name = 'COL1';
TABLE_NAME DATA_LENGTH
---------- -----------
TAB 100
VTAB 100