1) as best as it can, yes.
3) wrong, it'll cache that - it is rather easy to SEE. consider:
ops$tkyte%ORA10GR2> create table t ( x int, y int );
Table created.
ops$tkyte%ORA10GR2>
ops$tkyte%ORA10GR2> create or replace procedure foo
2 as
3 begin
4 insert into t values ( 1, 2 );
5 update t set x = 5;
6 delete from t;
7 merge into t using (select 1 x, 2 y from dual) d on (t.x = d.x) when matched then update set y = d.y;
8
9 execute immediate 'insert into t values ( 100, 200 )';
10 execute immediate 'update t set x = 500';
11 execute immediate 'delete from t where 1=1';
12 execute immediate 'merge into t using (select 10 x, 20 y from dual) d on (t.x = d.x) when matched then update set y = d.y';
13 end;
14 /
Procedure created.
ops$tkyte%ORA10GR2>
ops$tkyte%ORA10GR2> @trace
ops$tkyte%ORA10GR2> alter session set events '10046 trace name context forever, level 12';
Session altered.
ops$tkyte%ORA10GR2> exec foo
PL/SQL procedure successfully completed.
ops$tkyte%ORA10GR2> exec foo
PL/SQL procedure successfully completed.
ops$tkyte%ORA10GR2> exec foo
tkprof will show 1 parse, 3 executes - all cached in this caseINSERT INTO T VALUES ( 1, 2 )
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 3 0.00 0.00 0 1 23 3
********************************************************************************
UPDATE T SET X = 5
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 1 0 0
Execute 3 0.00 0.00 0 21 3 3
********************************************************************************
DELETE FROM T
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 1 0 0
Execute 3 0.00 0.00 0 21 6 3
********************************************************************************
MERGE INTO T USING (SELECT 1 X, 2 Y FROM DUAL) D ON (T.X = D.X) WHEN MATCHED
THEN UPDATE SET Y = D.Y
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 2 0 0
Execute 3 0.00 0.00 0 21 0 0
********************************************************************************
insert into t values ( 100, 200 )
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 3 0.00 0.00 0 1 5 3
********************************************************************************
update t set x = 500
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 1 0 0
Execute 3 0.00 0.00 0 21 3 3
********************************************************************************
delete from t where 1=1
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 1 0 0
Execute 3 0.00 0.00 0 21 6 3
********************************************************************************
merge into t using (select 10 x, 20 y from dual) d on (t.x = d.x) when
matched then update set y = d.y
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 3 0.00 0.00 0 2 0 0
Execute 3 0.00 0.00 0 21 0 0