We’ve a preparedStatement which needs to do multiple operations on the db, so all those sql statements are enclosed in a BEGIN-END block like
BEGIN
DELETE FROM...WHERE A=?..
UPDATE TABLE...WHERE B=?..
END;
But many reviewers said this will result in a hard parse. From my understanding hard parse is when an sql is not found in the shared pool, then the syntax, execution plan ..everything needs to be calculated again, but here shouldn’t Oracle treat them as individual sql statements.
How can I find out that oracle will do a hard parse or not on a given sql statement?
Bind variables work in PL/SQL blocks just as well as they do in SQL statements.
You can test this by running simple statements in a loop, then look at the parse counts in
v$sesstat.Create a simple table to use for inserting and deleting. Get initial parse counts.
This is what hard parsing looks like:
PL/SQL blocks with bind variables do not always hard parse. Note that the parse counts are cumulative, and they only increase very slightly here.