Is it possible to lock the table restricting reads from other sessions? I would more appreciate suggestions like “you can workaround it with …” than “Why do you need that?”.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
At least you acknowledge this is a odd request.
There are some things you could do to implement this. All of them require some redirection, which means the table must be owned by a separate schema, not the one users connect with. This is because Oracle does not have a mechanism for blocking reads, and a schema owner always has access to their tables; all we can do is deny other users access to our tables.
One option is to use a view. Most of the time it points to your table.
But when you want to deny access you switch it to a different, empty table (which obviously must have the same projection as YOUR_TABLE).
Then when you’ve finished you can run the first statement again.
This approach is relatively straightforward but requires issuing DDL. This means the account working on YOUR_TABLE also must have rights on the PUBLIC_USER.YOUR_TABLE. Also, issuing DDL will invalidate objects which have a dependency on the table (view).
So here is an alternative approach.
We have a different version of the view:
This will return all the rows in YOUR_TABLE or none or them, depending on the value of LOCK_TABLE.COL1. So you withdraw access to the table’s data you run
lock_the_table()and to grant it you rununlock_the_table().Why does Oracle make it so hard to be this? Because it is confusing to the application users. Oracle has implemented a multi-version concurrency model, which means we can always read tables, regardless of whether anybody else is working with the table. What you want to do flies in the face of that approach.