Hi Vanda
I will spare you my usual litany on why not to use dynamic SQL and that being "dynamic" is actually not a clever DB hack, but just a major indicator of that the developer has gained some confidence about SQL programming but is not very experienced in operating and running such systems later on.
Anyhow, in your code you've got two procedures and one table that interact with each other.
BLD_STMT_TBL will eventually drop table STMT_TBL.
BLD_TABLE however will eventually read from table STMT_TBL.
So the dependecies are
BLD_STMT_TBL --depends-on--> STMT_TBL and
BLD_TABLE --depends-on--> STMT_TBL.
As long as you run each procedure separately, you're running them in a single transaction.
But as soon as you call them from within a third procedure, you put them into the same transaction.
The drop of the table does affect the procedure that is called afterwards, because this procedure just became invalid and needs to be recompiled.
This typically happens automatically, but not within the same transaction.
That's why your procedure then fails based on the dependency error.
Agreed on the notion that the error message could/should be nicer.
However, mixing up DDL, DML and dynamic SQL really is a good way to run into issues like this.
- Lars