[20160313]繫結變數的分配長度4.txt

lfree發表於2016-03-13
[20160313]繫結變數的分配長度4.txt

--如果繫結變數中字串分配佔用空間的長度變化,oracle會建立子游標。
--參考連線:
http://blog.itpub.net/267265/viewspace-1993495/
http://blog.itpub.net/267265/viewspace-2024389/
http://blog.itpub.net/267265/viewspace-2050886/

--12c支援更長的字串,順便測試看看:

--關於設定12c支援字串長度,參考連結:

[20130915]12c新特性 varchar2支援32K長度.txt
http://blog.itpub.net/267265/viewspace-772855/

1.環境:
SCOTT@test01p> @ ver1

PORT_STRING                    VERSION        BANNER                                                                               CON_ID
------------------------------ -------------- -------------------------------------------------------------------------------- ----------
IBMPC/WIN_NT64-9.1.0           12.1.0.1.0     Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production              0

create table t (c1 varchar2(32767));

declare
v_c1 varchar2(32767);
  begin
   for i in 1..32767 loop
     v_c1 := rpad('X',i);
     execute immediate 'select count(*) from t where c1=:instring' using v_c1 ;
    end loop;
end;
/
commit;

--確定sql_id='9mrd273576n14'

2.看看結果:
SCOTT@test01p> @ 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         32 2016-03-13 22:16:21 VARCHAR2(32)    X
                         1 YES :INSTRING                     1        128 2016-03-13 22:16:21 VARCHAR2(128)   X
                         2 YES :INSTRING                     1       2000 2016-03-13 22:16:21 VARCHAR2(2000)  X

SYS@test>  @ hide _cursor_bind_capture_area_size
NAME                           DESCRIPTION                                  DEFAULT_VALUE SESSION_VALUE SYSTEM_VALUE
------------------------------ -------------------------------------------- ------------- ------------- ----------------
_cursor_bind_capture_area_size maximum size of the cursor bind capture area TRUE          400           400

--受隱含引數_cursor_bind_capture_area_size大小控制的影響,僅僅顯示3個子游標.

SCOTT@test01p> select sql_id, child_number, executions  from v$sql where sql_id = '9mrd273576n14';
SQL_ID        CHILD_NUMBER EXECUTIONS
------------- ------------ ----------
9mrd273576n14            0         32
                         1         96
                         2       1872
                         3       2000
                         4       4192
                         5       8194
                         6      16381
7 rows selected.

32,
32+96=128
32+96+1872=2000
32+96+1872+2000=4000
32+96+1872+2000+4192=8192
32+96+1872+2000+4192+8194=16386
32+96+1872+2000+4192+8194+16381=32767

--按照 32,128,2000,4000,8192,16386來分段.

SCOTT@test01p> select sql_id, child_number,executions, sum(executions) over (partition by sql_id order by child_number)  N20 from v$sql where sql_id = '9mrd273576n14' order by child_number;
SQL_ID        CHILD_NUMBER EXECUTIONS        N20
------------- ------------ ---------- ----------
9mrd273576n14            0         32         32
                         1         96        128
                         2       1872       2000
                         3       2000       4000
                         4       4192       8192
                         5       8194      16386
                         6      16381      32767
7 rows selected.

SYS@test> @ sharepool/shp4 9mrd273576n14
old  16:  WHERE kglobt03 = '&1'  or kglhdpar='&1' or kglhdadr='&1'
new  16:  WHERE kglobt03 = '9mrd273576n14'  or kglhdpar='9mrd273576n14' or kglhdadr='9mrd273576n14'
TEXT           KGLHDADR         KGLHDPAR         C40                                      KGLOBHD0         KGLOBHD6           KGLOBHS0   KGLOBHS6   KGLOBT16  N0_6_16        N20   KGLNAHSH KGLOBT03
-------------- ---------------- ---------------- ---------------------------------------- ---------------- ---------------- ---------- ---------- ---------- -------- ---------- ---------- -------------
子游標控制程式碼地址 000007FF55837E00 000007FF557C6518 select count(*) from t where c1=:instrin 000007FF57D18668 000007FF26B93788       4072      12144       7986    24202      24202 3396554788 9mrd273576n14
子游標控制程式碼地址 000007FF559F4180 000007FF557C6518 select count(*) from t where c1=:instrin 000007FF575476A0 000007FF26B93BD8       4072      12144       7986    24202      24202 3396554788 9mrd273576n14
子游標控制程式碼地址 000007FF59421708 000007FF557C6518 select count(*) from t where c1=:instrin 000007FF553BE988 000007FF5966EFB8       8144      12144       7986    28274      28274 3396554788 9mrd273576n14
子游標控制程式碼地址 000007FF2671D0B0 000007FF557C6518 select count(*) from t where c1=:instrin 000007FF55768408 000007FF5966F308       8144      12144       7986    28274      28274 3396554788 9mrd273576n14
子游標控制程式碼地址 000007FF57AB5150 000007FF557C6518 select count(*) from t where c1=:instrin 000007FF26E86EB8 000007FF5966F5D8      12216      16200       7986    36402      36402 3396554788 9mrd273576n14
子游標控制程式碼地址 000007FF59307998 000007FF557C6518 select count(*) from t where c1=:instrin 000007FF57A8FF98 000007FF5966F928      16288      12144       7986    36418      36418 3396554788 9mrd273576n14
子游標控制程式碼地址 000007FF26D6DC40 000007FF557C6518 select count(*) from t where c1=:instrin 000007FF590DECF0 000007FF5966FBF8      24432      12144       7986    44562      44562 3396554788 9mrd273576n14
父遊標控制程式碼地址 000007FF557C6518 000007FF557C6518 select count(*) from t where c1=:instrin 000007FF574F43A8 00                     8144          0          0     8144       8144 3396554788 9mrd273576n14
8 rows selected.




來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2056695/,如需轉載,請註明出處,否則將追究法律責任。

相關文章