You can't generate a plan from a PL/SQL block. You can only do so for SQL. So, take each of these DELETE statements and pull them out, replacing any PL/SQL variables with bind variable placeholders:
EXPLAIN PLAN FOR
DELETE FROM table1 t1
WHERE t1.ftcode = :FTCode
/
SELECT * FROM TABLE(dbms_xplan.display())
/
EXPLAIN PLAN FOR
DELETE FROM table2 t2
WHERE t2. ftcodet2 = :FTCode;
/
SELECT * FROM TABLE(dbms_xplan.display())
/
Note the :
symbol. That will make it a bind variable (though you aren't actually binding a value yet). That's enough to get an execution plan.
Now be advised that with heavy data skew and histograms in place with bind peeking enabled, Oracle could generate more than one child cursor due to the bind variable value itself, which could lead to a different plan depending on what value you bind. So sometimes you might want to try a literal:
EXPLAIN PLAN FOR
DELETE FROM table1 t1
WHERE t1.ftcode = 1234
/
SELECT * FROM TABLE(dbms_xplan.display())
/
To see if it makes a difference in the plan. Even that is not guaranteed to be what your code will do, because a literal may result in a plan different than a bind variable would. The only way to be absolutely sure what plan is being used is to actually observe it upon (or after) being executed. That would require SELECT ANY DICTIONARY
privs and some knowledge of how to navigate v$session
, v$active_session_history
, v$sql
and v$sql_plan
, which I will leave off any further discussion of to not prolong this post.
One more important point: when you look at a plan, learn to read it and understand what every step is doing and the number of executions of each step and row count coming from each step. Do NOT look at the COST
. That is a wasteful piece of information that Oracle should never have exposed. By definition Oracle will always choose the lowest cost plan, by its calculation. If it has made a mistake, then it has calculated the cost incorrectly, and the number is bogus. Therefore, for performance tuning there is no point at all in giving that number the slightest bit of attention. You have to understand how to read plans and understand how Oracle does table access, joins, sorts, etc.. in addition to knowing your data relationships, cardinality and volume in order to know whether it has chosen the right plan.