バインド変数は、SQL文と同じようにPL/SQLブロックで機能します。
これをテストするには、ループ内で単純なステートメントを実行してから、の解析カウントを確認しv$sesstat
ます。
挿入と削除に使用する簡単なテーブルを作成します。初期解析カウントを取得します。
create table test1(a number);
--Flush the pool, or else this test won't be repeatable.
alter system flush shared_pool;
select value, name
from v$sesstat natural join v$statname
where sid = sys_context('userenv', 'sid')
and name in ('parse count (total)', 'parse count (hard)');
47 parse count (total)
5 parse count (hard)
これは、ハード解析がどのように見えるかです。
begin
for i in 1 .. 10000 loop
execute immediate 'insert into test1 values('||i||')';
end loop;
commit;
end;
/
select value, name
from v$sesstat natural join v$statname
where sid = sys_context('userenv', 'sid')
and name in ('parse count (total)', 'parse count (hard)');
10072 parse count (total)
10007 parse count (hard)
バインド変数を持つPL/SQLブロックは、必ずしもハード解析されるとは限りません。解析カウントは累積的であり、ここではごくわずかしか増加しないことに注意してください。
begin
for i in 1 .. 10000 loop
execute immediate
'begin
delete from test1 where a = :i;
end;'
using i;
end loop;
commit;
end;
/
select value, name
from v$sesstat natural join v$statname
where sid = sys_context('userenv', 'sid')
and name in ('parse count (total)', 'parse count (hard)');
10106 parse count (total)
10019 parse count (hard)