I have a package that will be inserting a single parent record in one table, and dependent child records in another table with a FK on the parent_id. Each of these functions will be called by an external program, and all calls to insert children may not be contained within the same transaction.
I’m wondering if there is any way for me to avoid having to track the parent_id manually and pass it along in every procedure’s parameter list. I’ve considered using the sys_context, but don’t think that will work because it won’t be in a single transaction.
Are there any other strategies for this or do I just need to suck it up and pass the parent_id to every method?
You could just use a package variable like this:
The package variable persists as long as your database connection exists. This would not work in a stateless environment like a web application.
That said, I’d be in favour of keeping the procedure modular by passing the ID in each time. That way nothing unexpected can happen.