[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.
--如果绑定变量中字符串分配占用空间的长度变化,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.