4

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?

  • See http://stackoverflow.com/questions/205736/oracle-get-list-of-all-tables for discussion on user/all/dba tables. Disconnect disconnects. There is an "alter session set current_schema='newUser'" command, but that doesn't change users or permissions, it just specifies the default schema to use for unqualified names. – Glenn Mar 26 '12 at 23:12

1 Answers1

7

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;
DCookie
  • 42,630
  • 11
  • 83
  • 92
  • Can you please give an example to grant access of `dba_users` to a particular user `nonsys`, and then how to actually access it? Thanks a lot! –  Mar 26 '12 at 23:26