天天看點

[20160302]綁定變量的配置設定長度2.txt

[20160302]綁定變量的配置設定長度2.txt

--如果綁定變量中字元串配置設定占用空間的長度變化,oracle會建立子光标。

--參考連接配接:

<a href="http://blog.itpub.net/267265/viewspace-1993495/">http://blog.itpub.net/267265/viewspace-1993495/</a>

--oracle 可以通過一個10503事件設定大的緩存,測試看看:

$ oerr ora 10503

10503, 00000, "enable user-specified graduated bind lengths"

// *Cause:

// *Action:

1.環境:

SCOTT@book&gt; @  &amp;r/ver1

PORT_STRING                    VERSION        BANNER

------------------------------ -------------- --------------------------------------------------------------------------------

x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

create table t (c1 varchar2(4000));

-- ALTER SESSION SET EVENTS '10503 trace name context level &lt;buffer length&gt;, forever';

ALTER SESSION SET EVENTS '10503 trace name context level 2000, forever';

declare

v_c1 varchar2(4000);

  begin

   for i in 1..4000 loop

     v_c1 := rpad('X',i);

     execute immediate 'insert into t values (:instring) ' using v_c1 ;

    end loop;

end;

/

commit;

     execute immediate 'select count(*) from t where c1=:instring' using v_c1 ;

--确定sql_id='9mrd273576n14'

SCOTT@book&gt; select sql_id, child_number, executions  from v$sql where sql_id = '9mrd273576n14';

SQL_ID        CHILD_NUMBER EXECUTIONS

------------- ------------ ----------

9mrd273576n14            0       2000

9mrd273576n14            1       2000

SCOTT@book&gt; @ &amp;r/bind_cap 9mrd273576n14

C200

------------------------------------------

select count(*) from t where c1=:instring

SQL_ID        CHILD_NUMBER WAS NAME                   POSITION MAX_LENGTH LAST_CAPTURED       DATATYPE_STRING VALUE_STRING

------------- ------------ --- -------------------- ---------- ---------- ------------------- --------------- -------------

9mrd273576n14            0 YES :INSTRING                     1       2000 2016-03-02 15:39:23 VARCHAR2(2000)  X

                         1 YES :INSTRING                     1       4000 2016-03-02 15:39:23 VARCHAR2(4000)  X

--可以發現這樣僅僅存在2個光标。

SCOTT@book&gt; alter system flush shared_pool;

System altered.

SCOTT@book&gt; ALTER SESSION SET EVENTS '10503 trace name context  off';

Session altered.

--重新執行看看。

--也可以退出再登入執行看看。

9mrd273576n14            0         32

9mrd273576n14            1         96

9mrd273576n14            2       1872

9mrd273576n14            3       2000

--這種情況僅僅存在這種因素産生大量子光标的情況下可以考慮這種方式。