Tuesday, March 2, 2010

Jasper Report + Oracle CURSOR_SHARING='FORCE'

Notice that if i set the Oracle Initialization Parameter

CURSOR_SHARING = 'FORCE' or
CURSOR_SHARING = 'SIMILAR'

the Jasper Report (iReport) with UNION query does not work. It shall give the following error:

java sql sqlexception : no more data read from socket

To solve this, I have to tell the optimiser to switch off the cursor sharing feature for this query by inserting the phrase /*+ CURSOR_SHARING_EXACT */ into the query.

E.g.
SELECT /*+ CURSOR_SHARING_EXACT */ field 1 FROM TABLE 1
UNION
SELECT field 2 FROM TABLE 2

References:
1. Extract from http://www.psoug.org/reference/hints.html

Oracle can replace literals in SQL statements with bind variables, when it is safe to do so. This replacement is controlled with the CURSOR_SHARING initialization parameter. The CURSOR_SHARING_EXACT hint instructs the optimizer to switch this behavior off. In other words, Oracle executes the SQL statement without any attempt to replace literals with bind variables.

2. CURSOR_SHARING :
http://www.oracle.com/technology/oramag/oracle/06-jan/o16asktom.html

No comments:

Post a Comment