My Oracle Support Banner

Using DBMS_ADVANCED_REWRITE When Binds Are Present (Avoiding ORA-30353) (Doc ID 392214.1)

Last updated on FEBRUARY 15, 2019

Applies to:

Oracle Database - Enterprise Edition - Version 10.1.0.2 to 11.2.0.2 [Release 10.1 to 11.2]
Oracle Database Cloud Schema Service - Version N/A and later
Oracle Database Exadata Cloud Machine - Version N/A and later
Oracle Database Exadata Express Cloud Service - Version N/A and later
Oracle Cloud Infrastructure - Database Service - Version N/A and later
Information in this document applies to any platform.

Goal

When trying to use DBMS_ADVANCED_REWRITE to rewrite a query with bind variables in the where clause, the error ORA-30353 is signal.
This is a known and intended limitation in the functionality.

A rewrite of the query in spite of this limitation can still be accomplished, as shown in this article.

Here is a small testcase to demonstrate the above. It is assumed that the prerequisites for rewrite equivalence are satisfied in the current session i.e. user has execute privilege on DBMS_ADVANCED_REWRITE, query_rewrite_enabled=true and query_rewrite_integrity=trusted (or stale_tolerated)

NOTE: In the images and/or the document content below, the user information and data used represents fictitious data from the Oracle sample schema(s) or Public Documentation delivered with an Oracle database product. Any similarity to actual persons, living or dead, is purely coincidental and not intended in any manner. 

 

SQL> CREATE TABLE tableA (c1 VARCHAR2(10));

Table created.

SQL> INSERT INTO tableA VALUES ('A');

1 row created.

SQL> INSERT INTO tableA VALUES ('C');

1 row created.

SQL> CREATE TABLE tableB (c1 VARCHAR2(10));

Table created.

SQL> INSERT INTO tableB VALUES ('B');

1 row created.

SQL> INSERT INTO tableB VALUES ('C');

1 row created.

SQL> COMMIT;

Commit complete.

Consider the following query and its result without rewrite equivalence:

SQL> variable B1 varchar2(1)
SQL> exec :B1 := 'C';

PL/SQL procedure successfully completed.

SQL> SELECT c1 FROM tableA WHERE c1 != :B1;

C1
----------
A

We wish to transform it so that it selects from tableB instead:

SQL> exec sys.dbms_advanced_rewrite.declare_rewrite_equivalence ( -
> name => 'DUMMY', -
> source_stmt => 'SELECT c1 FROM tableA where c1 != :B1', -
> destination_stmt => 'SELECT c1 FROM tableB', -
> validate => FALSE, -
> rewrite_mode => 'GENERAL' -
> );

BEGIN sys.dbms_advanced_rewrite.declare_rewrite_equivalence ( name => 'DUMMY',
source_stmt => 'SELECT c1 FROM tableA where c1 != :B1', destination_stmt =>
'SELECT c1 FROM tableB', validate => FALSE, rewrite_mode => 'GENERAL' ); END;
*
ERROR at line 1:
ORA-30353: expression not supported for query rewrite
ORA-06512: at "SYS.DBMS_ADVANCED_REWRITE", line 29
ORA-06512: at "SYS.DBMS_ADVANCED_REWRITE", line 185
ORA-06512: at line 1

The message for ORA-30353 is:

30353, 00000, "expression not supported for query rewrite"
// *Cause: The select clause referenced UID, USER, ROWNUM, SYSDATE,
//         CURRENT_TIMESTAMP, MAXVALUE, a sequence number, a bind variable,
//         correlation variable, a set result,a  trigger return variable, a
//         parallel table queue column, collection iterator, etc.
//
// *Action: Remove the offending expression or disable the REWRITE option on
//          the materialized view.

Solution

To view full details, sign in with your My Oracle Support account.

Don't have a My Oracle Support account? Click to get started!


In this Document
Goal
Solution
References

My Oracle Support provides customers with access to over a million knowledge articles and a vibrant support community of peers and Oracle experts.