I have a sql script file that I use to install tables, trigger, sequences and finally a package. The package uses the tables created by the sql script file. The package is specified to run when an event occurs in the application i.e the package runs when an application trigger is fired.
All the package does is that it does a bulk select insert into a staging table. That is all it does.
Now, the issue is when I do a clean install the first time, the package is triggered and runs but does not insert data into the staging table. However, when the next event occurs the package is triggered and data is inserted into the staging stable and continues to function normally. So initially I thought it could be an initialization error.
However, when I drop all the objects created by the sql script file including the package and rerun the sql script file, the package works just fine when the first event occurs itself and continues to function normally.
So this cannot be an initialization error.
But again (just because I am losing my mind) I drop everything and rerun the script file, I find the same behavior I noticed the first time. Then I drop everything again and rerun the script file it works just fine the first time.
I have no idea why it works alternatively and this is so weird.
I would guess code is in an invalid (un-compiled) state. A trigger is created on the table which calls a package which has not yet been created. Then the package is created. After first run, the trigger code is automatically re-compiled by the server. In your creation script, after all the objects are created, run a script to compile invalid objects (
ALTER <object> COMPILE).Verify that this is the case by checking:
after creation, but before your event triggers.