**:hlu
test:本次實驗的環境是10.101.50.35開啟兩個session,乙個sid為138,乙個為135
connected to oracle database 10g enterprise edition release 10.2.0.4.0
connected as bsderp
sql>
sql> alter system flush shared_pool;
system altered
sql> set erveroutput on;
cannot set erveroutput
sql> set timing on;
sql> declare
2 type rc is ref cursor;
3 l_rc rc;
4 l_dummy all_objects.object_name%type;
5 l_start number default dbms_utility.get_time;
6 begin
7 for i in 1 .. 1000 loop
8 open l_rc for 'select object_name from all_objects where object_id = '||i;
通常寫法
9 fetch l_rc into l_dummy;
10 close l_rc;
11 end loop;
12 dbms_output.put_line(round((dbms_utility.get_time-l_start)/100,2)|| 'seconds ...');
13 end;
14 /
pl/sql procedure successfully completed
executed in 24.547 seconds
執行時間
sql>
sql>
sql>
sql>
sql> declare
2 type rc is ref cursor;
3 l_rc rc;
4 l_dummy all_objects.object_name%type;
5 l_start number default dbms_utility.get_time;
6 begin
7 for i in 1 .. 1000 loop
8 open l_rc for 'select object_name from all_objects where object_id = :x' using i;
繫結變數
9 fetch l_rc into l_dummy;
10 close l_rc;
11 end loop;
12 dbms_output.put_line(round((dbms_utility.get_time-l_start)/100,2)|| 'seconds ...');
13 end;
14 /
pl/sql procedure successfully completed
executed in 0.25 seconds
執行時間
可以和普通的寫法比較下,看看差別是多少倍
參考:上面同樣目的的兩條sql執行後對於軟硬解析的影響:
/**解釋一下v$sesstat中相關取值的重要概念
1 > opened cursors current (當前單個session開啟的cursors數量)
2 > parse count (hard) (當前session硬解析次數)
3 > parse count (total) (當前session解析總次數)
4 > session cursor cache count (設定session_cached_cursors引數後,"相同"sql被解析3次後被cache在session cursor cache中的數量
5 > session cursor cache hits (軟軟解析的次數 a "softer" soft parse )
6 > 手工計算一下軟解析次數parse count (total) - session cursor cache hits - parse count (hard) = parse count(soft)
oracle 繫結變數的用法
1.前言。oracle10g後,使用繫結變數更能提高效率。以下 的文章。讓oracle自己繫結變數 set serverout on set timing on declare l sql varchar l count number l param varchar l param varchar ...
MySQl的繫結變數特性
從mysql 4.1版本開始,就支援伺服器端的繫結變數 prepared statement 這大大提高了客戶端和伺服器端資料傳輸的效率。你若使用乙個支援新協議的客戶端,如mysql c api,就可以使用繫結變數功能了。另外,j a和.net的也都可以使用各自的客戶端connector j和con...
繫結變數對效能的影響
使用繫結變數對效能的影響,oracle 程式設計入門經典 beginning oracle programming 中的例子 sql alter system flush shared pool sql set serveroutput on declare l start number l cnt...