How to fix the Oracle error QSM-01321: query rewrite not possible because materialized view string has TRUSTED constraints in ENFORCED integrity mode?

In this post, you’ll learn more about the Oracle ErrorQSM-01321: query rewrite not possible because materialized view string has TRUSTED constraints in ENFORCED integrity mode with the details on why you receive this error and the possible solution to fix it.

Oracle Error Description

QSM-01321: query rewrite not possible because materialized view string has TRUSTED constraints in ENFORCED integrity mode

Reason for the Error QSM-01321: query rewrite not possible because materialized view string has TRUSTED constraints in ENFORCED integrity mode

A stale materialized view created with USING TRUSTED CONSTRAINTS clause cannot be used when the query rewrite integrity mode is set ENFORCED.

How to fix the Error QSM-01321: query rewrite not possible because materialized view string has TRUSTED constraints in ENFORCED integrity mode ?

You can fix this error in Oracle by following the below steps

Alter materialized view such that it has the ENFORCED CONSTRAINTS ALTER MATERIALIZED VIEW REFRESH USING ENFORCED CONSTRAINTS