实例化视图“预建表的形状与定义查询不匹配”

时间:2019-01-11 21:47:38

标签: sql oracle plsql

日期列导致“预建表格的形状与定义查询不匹配”错误。

我删除了该列,并使用下面的ddl读取了该列。我仍然看到相同的错误。

ALTER TABLE schema.table DROP COLUMN column_name;

ALTER TABLE schema.table ADD column_name DATE;

CREATE 
    MATERIALIZED VIEW schema.table ON PREBUILT TABLE WITH REDUCED PRECISION
        USING INDEX REFRESH ON DEMAND COMPLETE
        USING DEFAULT LOCAL ROLLBACK SEGMENT DISABLE QUERY REWRITE AS SELECT
... column names ...
from schema.table1;

日期列导致此问题呢?有趣的是,这甚至不是新的专栏。该列已经存在,另外48个。当此列开始起作用时,我正在尝试向MView添加第50列。

更令人困惑的是,同样的create materialized view在另一个环境中也能正常工作。跨环境的表定义在各个字符之间完全相同。我知道是因为我在两者之间做了区分。

我能够诊断出此列是罪魁祸首的方法是一次删除一列并尝试创建实例化视图。我在35列后找到了它。真惨这样做有更好的办法吗?

1 个答案:

答案 0 :(得分:0)

即使您选择的数据类型大小等于或小于表列大小,也要将您选择的值保留在预建表列的数据类型中

create table person_mvw
(
person_number varchar2(20)
person_name varchar2(50)
person_address varchar2(50)
);

-- This may not work
create materialized view person_mvw
on prebuilt table as
select
customer_nbr
, customer_firstname || ' ' || customer_lastname
customer_address
from customer 
;

-- Try this even if the datatype size is same or smaller than the table column size, even if you have used substr function to reduce the size.
create materialized view person_mvw
on prebuilt table as
select
cast(customer_nbr as varchar2(20))
, cast ((customer_firstname || ' ' || customer_lastname) as varchar2(50))
, cast (customer_address as varchar2(50))
from customer 
;