바인드 변수는 단지뿐만 아니라 PL/SQL 블록에서 작동 :
여기에 설명하고 어떻게되는지 보여주는 좋은 동영상입니다.
루프에서 간단한 명령문을 실행하여 테스트하고 v$sesstat
의 구문 분석 횟수를 살펴볼 수 있습니다.
삽입 및 삭제에 사용할 간단한 테이블을 만듭니다. 초기 구문 분석 횟수를 가져옵니다. 항상 열심히 분석하지 않는 바인드 변수와
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 블록 :
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
'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)