简体   繁体   中英

Materialized view "shape of prebuilt table does not match definition query"

A date column is causing "shape of prebuilt table does not match definition query" error.

I deleted the column and readded it with the ddl below. I still see the same error.

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;

What about the date column is causing this issue? Funny thing is this isn't even a new column. This column was already existing with 48 others. I was trying add a 50th column to the MView when this column started acting up.

What is even more puzzling is this same create materialized view works fine in another environment. The table definitions across environments are exactly same character to character. I know because I did a diff between both of them.

The way I was able to diagnose that this column was the culprit is by dropping one column at a time and trying to create the materialized view. I found it after 35 columns. This is miserable. Is there a better of doing this?

Just had a problem like this, maybe not your case, but good for try/know, its related with sqldeveloper, doesn't know if its your case.

A friend and I were trying to recreate a table and materialized view, my friend copied the DDL and simple removed one column, but when executing he got that "shape of prebuilt table does not match definition query" error.

He passed me the same code and on my machine it worked.

The thing is that some of the properties of the sqldeveloper (screenshot provided) were different in our settings.

We highly suspect on (we have to confirm) Length and Date Format (in spanish in the screenshot), also matched the decimal and group settings, just marked what we had different, so when he changed settings to match mine, the script worked.

The thing is that you define the type of data for the table, but the materialized view seems to get these from the settings and that affects the "shape" of the view.

西班牙语 sqldeveloper 设置

Cast the value you are selecting into the data type of the prebuilt table column, even if the select datatype size is same or smaller than the table column size

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 
;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM