SELECT owner, table_name
FROM dba_tables
This is assuming that you have access to the DBA_TABLES
data dictionary view. If you do not have those privileges but need them, you can request that the DBA explicitly grants you privileges on that table, or, that the DBA grants you the SELECT ANY DICTIONARY
privilege or the SELECT_CATALOG_ROLE
role (either of which would allow you to query any data dictionary table). Of course, you may want to exclude certain schemas like SYS
and SYSTEM
which have large numbers of Oracle tables that you probably don't care about.
Alternatively, if you do not have access to DBA_TABLES
, you can see all the tables that your account has access to through the ALL_TABLES
view:
SELECT owner, table_name
FROM all_tables
Although, that may be a subset of the tables available in the database (ALL_TABLES
shows you the information for all the tables that your user has been granted access to).
If you are only concerned with the tables that you own, not those that you have access to, you could use USER_TABLES
:
SELECT table_name
FROM user_tables
Since USER_TABLES
only has information about the tables that you own, it does not have an OWNER
column – the owner, by definition, is you.
Oracle also has a number of legacy data dictionary views-- TAB
, DICT
, TABS
, and CAT
for example-- that could be used. In general, I would not suggest using these legacy views unless you absolutely need to backport your scripts to Oracle 6. Oracle has not changed these views in a long time so they often have problems with newer types of objects. For example, the TAB
and CAT
views both show information about tables that are in the user's recycle bin while the [DBA|ALL|USER]_TABLES
views all filter those out. CAT
also shows information about materialized view logs with a TABLE_TYPE
of "TABLE" which is unlikely to be what you really want. DICT
combines tables and synonyms and doesn't tell you who owns the object.
You can use a subquery for this like
select *
from
( select *
from emp
order by sal desc )
where ROWNUM <= 5;
Have also a look at the topic On ROWNUM and limiting results at Oracle/AskTom for more information.
Update:
To limit the result with both lower and upper bounds things get a bit more bloated with
select * from
( select a.*, ROWNUM rnum from
( <your_query_goes_here, with order by> ) a
where ROWNUM <= :MAX_ROW_TO_FETCH )
where rnum >= :MIN_ROW_TO_FETCH;
(Copied from specified AskTom-article)
Update 2:
Starting with Oracle 12c (12.1) there is a syntax available to limit rows or start at offsets.
SELECT *
FROM sometable
ORDER BY name
OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY;
See this answer for more examples. Thanks to Krumia for the hint.
Best Solution
You can check which privileges a certain user was granted using system views:
USER_SYS_PRIVS
- System privileges granted to current userDBA_SYS_PRIVS
- System privileges granted to users and rolesUSER_TAB_PRIVS
- Grants on objects for which the user is the grantor, grantee, or ownerALL_TAB_PRIVS
- Grants on objects for which the user is the grantor, grantee, owner, or an enabled role orPUBLIC
is the granteeDBA_TAB_PRIVS
- Grants on all objects in the databaseDBA_ROLES All
- roles that exist in the databaseDBA_ROLE_PRIVS
- Roles granted to users and rolesDBA_SYS_PRIVS
- System privileges granted to users and rolesDBA_TAB_PRIVS
- All grants on objects to users and rolesROLE_ROLE_PRIVS
- Roles that are granted to rolesROLE_SYS_PRIVS
- System privileges granted to rolesROLE_TAB_PRIVS
- Table privileges granted to rolesTo check, for example, which system privileges a user has that another user was not granted, and vice versa, you could use (you'd have to run it as
SYS
user):Output:
To check if a user was granted the
EXECUTE ON sys.dbms_aqjms
privilege, you would issue the following query:Output:
If you don't have access to
SYS
user, you can query theuser_
versions of system tables to check privileges owned by the user you are currently logged as. Then you can compare results with privileges of another user.You have take into account, that user may by granted role, and that roles may be granted to roles, so you will also have to compare roles granted to each user.