What to do to change materialized view column size when under line table column size changed? This is oracle 11gR2 db on Linux. I tried recompile the MV, it didn't work. Please do not auto migrate this question to another database site, I want to stay here in stackoverflow. Thanks!
In generic terms, you use the ALTER TABLE command followed by the table name, then the MODIFY command followed by the column name and new type and size. Here is an example: ALTER TABLE tablename MODIFY columnname VARCHAR(20) ; The maximum width of the column is determined by the number in parentheses.
If you drop a materialized view, then any compiled requests that were rewritten to use the materialized view will be invalidated and recompiled automatically. If the materialized view was prebuilt on a table, then the table is not dropped, but it can no longer be maintained by the materialized view refresh mechanism.
No, you cannot alter the query of a materialized view without dropping it. The CREATE MATERIALIZED VIEW syntax does not support that feature. The ALTER MATERIALIZED VIEW is used to modify an existing materialized view in one or more of the following ways: To change its storage characteristics.
If you alter the table you must also alter the materialized view.
--Create simple table and materialized view
create table test1(a varchar2(1 char));
create materialized view mv_test1 as select a from test1;
--Increase column width of column in the table
alter table test1 modify (a varchar2(2 char));
--Insert new value that uses full size
insert into test1 values('12');
--Try to compile and refresh the materialized view
alter materialized view mv_test1 compile;
begin
dbms_mview.refresh(user||'.MV_TEST1');
end;
/
ORA-12008: error in materialized view refresh path
ORA-12899: value too large for column "JHELLER"."MV_TEST1"."A" (actual: 2, maximum: 1)
ORA-06512: at "SYS.DBMS_SNAPSHOT", line 2563
ORA-06512: at "SYS.DBMS_SNAPSHOT", line 2776
ORA-06512: at "SYS.DBMS_SNAPSHOT", line 2745
ORA-06512: at line 3
--Increase column width of column in the materialized view and refresh
alter materialized view mv_test1 modify (a varchar2(2 char));
begin
dbms_mview.refresh(user||'.MV_TEST1');
end;
/
select * from mv_test1;
A
--
12
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With