Friday, March 12, 2010

给宠物狗的鞋子 : 一双/两双?

周五,吃了晚饭和同事到新开的宠物店闲逛。一边赞叹琳琅满目的宠物食/用品,同事指了指包装精美的四只宠物狗鞋子。

下意识的,我回应说“不错哦,有两双可以替换”。。。。

“两双?”,同事楞了楞说道。

我说“对啊,四只不就两双吗?”。。。。

“狗有四只脚。。。。”

哈哈,惯性思维。总想着人就一双两只鞋呗,所以见到四只鞋子就理所当然的以为是两双,还“替换”呢!

其实日常工作中,常有因为惯性思维而闹笑话的事,很多时候当事人并不知晓犯了什么错误,就像我一样,愣是得意着。

注:请不要咬文嚼字计较四只,该说是一套/一双/两双?重点在于“替换” 与 “惯性思维”

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