This does not distinguish between the owner and the scheme.
But I always struggled with the idea that I create N number of users .... when I want each of these users to "consume" (aka, use) one scheme.
This guy shows how to do this (for N number of users ... is "redirected" to one scheme.
I will also embed his code, through an independent link, the URL will die in the future.
http://www.oracle-base.com/articles/misc/schema-owners-and-application-users.php
He has a second synonym approach. But I only insert the version of CURRENT_SCHEMA. AGAIN, I do not relate to this. I just hate it when someone says βyour answer is on this linkβ and BOOM, the link is dead .: & L;
.................................................. ....
(from http://www.oracle-base.com/articles/misc/schema-owners-and-application-users.php )
CURRENT_SCHEMA Approach
This method uses the session attribute CURRENT_SCHEMA to automatically point application users to the correct schema.
First, we create the schema owner and application user.
CONN sys/password AS SYSDBA -- Remove existing users and roles with the same names. DROP USER schema_owner CASCADE; DROP USER app_user CASCADE; DROP ROLE schema_rw_role; DROP ROLE schema_ro_role; -- Schema owner. CREATE USER schema_owner IDENTIFIED BY password DEFAULT TABLESPACE users TEMPORARY TABLESPACE temp QUOTA UNLIMITED ON users; GRANT CONNECT, CREATE TABLE TO schema_owner; -- Application user. CREATE USER app_user IDENTIFIED BY password DEFAULT TABLESPACE users TEMPORARY TABLESPACE temp; GRANT CONNECT TO app_user;
Please note that the application user can connect, but does not have table quotas or privileges for creating objects.
Then we create several roles to allow read-only and read-only access.
CREATE ROLE schema_rw_role; CREATE ROLE schema_ro_role;
We want to provide the user with the ability to read and write circuit objects to users, so we provide an appropriate role.
GRANT schema_rw_role TO app_user;
We need to make sure that the user of the application has its own default scheme, indicating the owner of the scheme, so we create an AFTER LOGON trigger for this.
CREATE OR REPLACE TRIGGER app_user.after_logon_trg AFTER LOGON ON app_user.SCHEMA BEGIN DBMS_APPLICATION_INFO.set_module(USER, 'Initialized'); EXECUTE IMMEDIATE 'ALTER SESSION SET current_schema=SCHEMA_OWNER'; END; /
Now we are ready to create an object from the owner of the circuit.
CONN schema_owner/password CREATE TABLE test_tab ( id NUMBER, description VARCHAR2(50), CONSTRAINT test_tab_pk PRIMARY KEY (id) ); GRANT SELECT ON test_tab TO schema_ro_role; GRANT SELECT, INSERT, UPDATE, DELETE ON test_tab TO schema_rw_role;
Please note how privileges are granted to the respective roles. Without this, objects will not be visible to the application user. Now we have a current schema owner and application user.
SQL> CONN app_user/password Connected. SQL> DESC test_tab Name Null? Type ----------------------------------------------------- -------- ------------------------------------ ID NOT NULL NUMBER DESCRIPTION VARCHAR2(50) SQL>
This method is ideal when the user of the application is just an alternative entry point into the main circuit, without requiring their own objects.