Code:
ops$[email]tkyte@ORA817DEV.US.ORACLE.COM[/email]> create table emp as select * from scott.emp;
Table created.
ops$[email]tkyte@ORA817DEV.US.ORACLE.COM[/email]> create table run_stats ( runid varchar2(15),
name varchar2(80), value int );
Table created.
ops$[email]tkyte@ORA817DEV.US.ORACLE.COM[/email]> create or replace view stats
2 as select ’STAT...’ || a.name name, b.value
3 from v$statname a, v$mystat b
4 where a.statistic# = b.statistic#
5 union all
6 select ’LATCH.’ || name, gets
7 from v$latch;
View created.
ops$[email]tkyte@ORA817DEV.US.ORACLE.COM[/email]> column name format a40
ops$[email]tkyte@ORA817DEV.US.ORACLE.COM[/email]> declare
2 l_start number;
3 l_cnt number;
4 begin
5 execute immediate ’alter session set session_cached_cursors=0’;
6 insert into run_stats select ’before’, stats.* from stats;
7
8 l_start := dbms_utility.get_time;
9 for i in 1 .. 1000
10 loop
11 execute immediate ’select count(*) from emp’ into l_cnt;
12 end loop;
13 dbms_output.put_line( (dbms_utility.get_time-l_start) || ’ hsecs’ );
14
15 execute immediate ’alter session set session_cached_cursors=100’;
16 insert into run_stats select ’after 1’, stats.* from stats;
17
18 l_start := dbms_utility.get_time;
19 for i in 1 .. 1000
20 loop
21 execute immediate ’select count(*) from emp’ into l_cnt;
22 end loop;
23 dbms_output.put_line( (dbms_utility.get_time-l_start) || ’ hsecs’ );
24
25 insert into run_stats select ’after 2’, stats.* from stats;
26 end;
27 /
45 hsecs
35 hsecs
PL/SQL procedure successfully completed.
so, session cached cursors RAN faster (i ran this a couple of times, there were no hard parses going on. But the real good news is:因此,在session中缓存游标可以运行的更快(我运行了好几次,没有硬解析的发生),真正可喜的消息是:
Code:
ops$[email]tkyte@ORA817DEV.US.ORACLE.COM[/email]> select a.name, b.value-a.value run1,
c.value-b.value run2,
2 ( (c.value-b.value)-(b.value-a.value)) diff
3 from run_stats a, run_stats b, run_stats c
4 where a.name = b.name
5 and b.name = c.name
6 and a.runid = ’before’
7 and b.runid = ’after 1’
8 and c.runid = ’after 2’
9 and (c.value-a.value) > 0
10 and (c.value-b.value) <> (b.value-a.value)
11 order by abs( (c.value-b.value)-(b.value-a.value))
12 /
NAME RUN1 RUN2 DIFF
LATCH.checkpoint queue latch 3 4 1
LATCH.redo allocation 30 31 1
STAT...consistent gets 5088 5089 1
STAT...deferred (CURRENT) block cleanout 2 3 1
applications
STAT...calls to get snapshot scn: kcmgss 5019 5018 -1
STAT...enqueue releases 10 9 -1
STAT...execute count 1015 1014 -1
STAT...opened cursors cumulative 1015 1014 -1
STAT...parse count (total) 1015 1014 -1
STAT...session cursor cache count 0 1 1
STAT...redo entries 28 27&nb
3COME考试频道为您精心整理,希望对您有所帮助,更多信息在http://www.reader8.net/exam/