Reputation:
I am new to Oracle database. I see that if I connect as sys
user, I can do
select * from dba_users;
But once I have done conn nonsys@dbid
, I can no longer do that; I will get an error saying
ORA-00942: table or view does not exist
select * from sys.dba_users;
is not working either.
Could you please explain why this is and how I can do select * from dba_users;
after connected as a non-sys user?
Also, disconnect
makes me totally disconnected; is it possible to only "exit" current user and back to sys
in sqlplus and if so, how to do that?
Upvotes: 4
Views: 22628
Reputation: 43533
The DBA_* views in Oracle contain information about ALL objects in the database regardless of ownership. Only administrative accounts have access to these views by default. This is done for security reasons. In order to have a "normal" user gain access to these views, they must be granted access to them, either directly on a per-view basis, or globally through such system privileges as SELECT ANY TABLE (not recommended). Better to grant access to the actual DBA_ view the user really needs. Generally, the ALL_ views will give a typical user all the information they require.
To leave the current user session and connect as another user, use the CONNECT command:
CONNECT sys/pw as sysdba
EDIT:
The owner of an object can grant access to any of their objects to another user or role via the GRANT command:
GRANT SELECT ON dba_users TO nonsys;
Performed as the user SYS, this would grant select access to the dba_users view to the user nonsys.
Once the grant is performed, the user nonsys will be able to select from this view via the SELECT statement:
SELECT * FROM dba_users;
Upvotes: 7