Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What to do to change materialized view column size when under line table column size changed?

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!

like image 652
magqq Avatar asked Dec 20 '12 19:12

magqq


People also ask

How do you modify the size of a column?

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.

What happens to materialized view if table is dropped?

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.

Can we alter materialized view?

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.


1 Answers

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
like image 99
Jon Heller Avatar answered Sep 23 '22 23:09

Jon Heller