oracle绑定变量的测试

绑定变量的测试[@more@]

10:16:39 scott@bus> select * from v$version
10:16:54 2 ;

BANNER
================================================================
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
PL/SQL Release 9.2.0.4.0 - Production
CORE 9.2.0.3.0 Production
TNS for 32-bit Windows: Version 9.2.0.4.0 - Production
NLSRTL Version 9.2.0.4.0 - Production

已用时间: 00: 00: 00.00

未用绑定变量
00:28:20 scott@bus>ed
已写入文件 afiedit.sql

1 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
8 loop
9 open l_rc for
10 'select object_name from all_objects
11 where object_id = ' || i;
12 fetch l_rc into l_dummy;
13 close l_rc;
14 end loop;
15 dbms_output.put_line(round((dbms_utility.get_time-l_start)/100,2)||
16 ' seconds...');
17* end;
00:28:47 scott@bus>/
32.66 seconds...

PL/SQL 过程已成功完成。

已用时间: 00: 00: 33.06
已用绑定变量
00:30:38 scott@bus>ed
已写入文件 afiedit.sql

1 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
8 loop
9 open l_rc for
10 'select object_name from all_objects
11 where object_id = :x' using i;
12 fetch l_rc into l_dummy;
13 close l_rc;
14 end loop;
15 dbms_output.put_line(round((dbms_utility.get_time-l_start)/100,2)||
16 ' seconds...');
17* end;
00:31:12 scott@bus>/
2.14 seconds...

PL/SQL 过程已成功完成。

已用时间: 00: 00: 02.01

通过以上的测试可以看出,使用绑定变量比未用绑定变量的效率要高的多。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/802415/viewspace-823033/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/802415/viewspace-823033/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值