we've got an Oracle 11g Schema that our application uses to select, insert and update, but we've had a request from one of our customers to provide read-only access to the same base tables and views owned by the application.
Other than synonym'ing all of the application owned tables into a new account (or making the synonyms public), how would I go about doing this?
Any help or pointers to the approach or Oracle feature I should be looking at would be most appreciated, thank you!
You'll need a separate account to grant the read-only access to. I would suggest adding a role that you grant read-only access to as well-- you can then re-use that role if more users need this access in the future.
Once that is done, the new account will need to prefix the table names with the schema name to select the data. Alternatively, you could create public synonyms for each object (you can add another EXECUTE IMMEDIATE to each loop in the code above). Or you could have the user run the command
on login. You could also create a login trigger in the new account that would do this automatically. That will cause
<<schema name>>
to be implicitly added as the schema prefix. It does not affect the privileges of the session-- the user still has the read-only privileges, the default schema name has just been changed.I created the new_customer_account without quotas as sysdba:
The application_user granted the select-right on the relevant views (and/or tables):
After that, the new_customer_account creates new Synonyms:
I'm pretty sure that you have to create a new account, and only grant select to that user.