CREATE OR REPLACE FUNCTION get_value_dyn(p_empno IN NUMBER, p_cname IN VARCHAR2)
RETURN VARCHAR2
AS
l_value VARCHAR2(4000);
BEGIN
EXECUTE IMMEDIATE
'SELECT ' || p_cname || ' FROM emp WHERE empno = :x'
INTO l_value
USING p_empno;
RETURN l_value;
END;
/
CREATE OR REPLACE FUNCTION get_value_static(p_empno IN NUMBER, p_cname IN VARCHAR2)
RETURN VARCHAR2
AS
l_value VARCHAR2(4000);
BEGIN
SELECT DECODE(UPPER(p_cname),'ENAME',ename
,'EMPNO',empno
,'HIREDATE',TO_CHAR(hiredate,'yyyymmdd') )
INTO l_value
FROM emp
WHERE empno = p_empno;
RETURN l_value;
END;
/
EXEC runstats_pkg.rs_start;
DECLARE
l_dummy VARCHAR2(30);
BEGIN
FOR i IN 1 .. 500
LOOP
FOR x IN (SELECT empno FROM emp)
LOOP
l_dummy := get_value_dyn(x.empno, 'ENAME');
l_dummy := get_value_dyn(x.empno, 'EMPNO');
l_dummy := get_value_dyn(x.empno, 'HIREDATE');
END LOOP;
END LOOP;
END;
/
EXEC runstats_pkg.rs_middle;
DECLARE
l_dummy VARCHAR2(30);
BEGIN
FOR i IN 1 .. 500
LOOP
FOR x IN (SELECT empno FROM emp)
LOOP
l_dummy := get_value_static(x.empno, 'ENAME');
l_dummy := get_value_static(x.empno, 'EMPNO');
l_dummy := get_value_static(x.empno, 'HIREDATE');
END LOOP;
END LOOP;
END;
/
EXEC runstats_pkg.rs_stop(1000);
Run1 ran in 1102 hsecs
Run2 ran in 703 hsecs
run 1 ran in 156.76% of the time
Name Run1 Run2 Diff
STAT...session cursor cache ya 21,003 4 -20,999
STAT...opened cursors cumulati 21,005 5 -21,000
STAT...parse count (total) 21,005 5 -21,000
LATCH.shared pool 63,565 21,566 -41,999
LATCH.library cache pin 127,062 43,064 -83,998
LATCH.library cache 127,087 43,088 -83,999
Run1 latches total versus runs -- difference and pct
Run1 Run2 Diff Pct
463,431 253,318 -210,113 182.94%
- 강좌 URL : http://www.gurubee.net/lecture/3575
- 구루비 강좌는 개인의 학습용으로만 사용 할 수 있으며, 다른 웹 페이지에 게재할 경우에는 출처를 꼭 밝혀 주시면 고맙겠습니다.~^^
- 구루비 강좌는 서비스 제공을 위한 목적이나, 학원 홍보, 수익을 얻기 위한 용도로 사용 할 수 없습니다.