I know this can be done, because I’ve seen it at my last workplace, but I don’t know how to replicate!
Basically, there is a MASTER user who has write privileges for all our tables. In our application’s DB adapter connection settings, we use DEFAULT_SCHEMA: MASTER
I have created a new test user for myself (on the same database as the master user, not using a database link) so that I can freely create test data without messing with real data. Then copied a table for my test user so that I can freely manipulate data: create table SIMMBOT.real_data_table as select * from MASTER.real_data_table
The problem is that I don’t know how to set up the connection so that Oracle knows to override MASTER.real_data_table with my own SIMMBOT.real_data_table. I have a hunch that you can’t actually do that in the connection settings… so starting from square one, what would I have to do to set up test tables like this? Something like a shared schema?
If your code is using fully qualified table names (i.e.
MASTER.real_data_tableorSIMMBOT.real_data_table) then there is no way from a configuration standpoint to change what object is being referred to.Assuming, however, that your code is not using a fully qualified table name– if it is just selecting from
real_data_table, then Oracle will first look for an object in the current schema with that name then look for a public synonym with that name.If you connect as
MASTER, you can change the current schemaOnce you’ve done that, all unqualified references to a table name will resolve to tables in the
SIMMBOTschema. Note that theMASTERuser would need to be granted appropriate access on the objects in theSIMMBOTschema separately– setting the current schema only affects name resolution, not privileges. TheSIMMBOTschema would also need to have every table that the code wants to reference– there is no way to specify a hierarchy for resolving unqualified names. You can’t tell Oracle to first resolve unqualified names in theSIMMBOTschema and then theMASTERschema.An alternative would be to create synonyms for each table and manipulate the synonyms to reference your table for some or all users. If your application logged in as a third user that did not own any objects–
APP_USERfor example– you could create either private synonyms in theAPP_USERschema that pointed to different objects in different schemas–or you could create public synonyms that would apply to all users (other than those that owned the objects)