List of usernames in oracle - oracle

I need to get a list of all users and their tables and details.
For Example : https://www.google.com/search?q=oracle+user&source=lnms&tbm=isch&sa=X&ved=0ahUKEwi-td2pjcPMAhXEFh4KHdMAAVcQ_AUIBygB&biw=1175&bih=621#tbm=isch&q=oracle+user++sql+developer&imgrc=Qvmfp57HchgwgM%3A
In the above screen towards left there is red color symbol (User) , SO i need the username, associated tables(under that user) and atrributes in that table. Is this possible. for all users.
Thanks
Addy

ALL USERS, ALL TABLES, 'and details'
So do you really want ALL the users? Because many users are system users - users that own objects that the database itself uses, SYS being the biggest example. You could have dozens of these accounts. I'm guessing you don't want them.
All tables, tables in the recycle bin, tables there for materialized views, do you want those too?
And 'details'. Do you want their created date, their columns, their storage parameters? The more you want, the bigger and uglier your query is going to get.
All that being said, you pointed to a screenshot of Oracle SQL Developer. It contains a data modeling feature. Use it. Reverse engineer the users you really want into a data model. And then use the data dictionary reports it offers to give you the info you want.
You have to figure out what you REALLY want first though.
I talk about how to do the RE in the data modeler here.

You can start from this:
select *
from dba_tables t
inner join dba_tab_columns
using(owner, table_name)
This will give all the tables and columns, with some informations about tablespace, the type of the columns, and so on

This shows all the users and all their tables except for SYS and SYSTEM
SELECT owner, table_name
FROM All_All_Tables
WHERE owner NOT IN ('SYS','SYSTEM')
ORDER BY 1,2
Runs on Oracle 10, 11

Related

How to view other users' objects like mine in Oracle SQL Developer?

When I access other users' objects, I can do something like
select * from user_2.booking_table;
given that I have the privileges over user_2's objects.
Using the console, I know I can do
alter session set current_schema=user_2;
to avoid prefixing user_2 in front of object's name - so I can do
select * from booking_table;
as if booking_table is my table without specifying user_2 each time.
If I want to bring similar idea to GUI client...
Using Oracle SQL Developer, under each connection, I know I can browse other users' objects under the tree node Other Users > user_2 > Tables/Views/Indexes etc...
Is there anyway I can "import" user_2's objects so that they appear under my Tables, Views, Indexes, etc under the connection, as if they look like they are my objects?
No. We show you what you have, or what other schemas have.
The only way to get close to what you're looking for is if you were to create synonyms to tables in other schemas, then you can ask SQL Developer to present those as TABLES in your connection list.
I'm logged in as a user with an 'empty' schema, at least as far as tables are concenred.
I enable this filter check item, and click 'OK' -
I talk about this in detail here.
Disclaimer: I'm the product manager for Oracle SQL Developer.

:APP_USER usage in SQL query. Oracle Application Express (Apex) 5.0.4

I want to use session variable :APP_USER in query in selection database statement like this:
select * from :APP_USER.data
I have users john.doe and johny.b.
I have table john.doe.data and i want to get all data from this table. Also i have table johny.b.data and when johny.b will login in, I want to get data from table johny.b.data.
I hope you understand my plan, so it is like every user have own data table and I want to display table according to logged in user. What will be the right way to do this?
I would say this would be possible but shouldn't be done. You'd be better off doing select * from apex_user.table (prefix not needed) where column = :APP_USER and having them all in one big table or having a different table (but same apex_schema) per user. How you'd go about creating this table is up to you - you could select a pseudo-table from dual and then only create it when necessary to prefent any table not found issues.
You'll no doubt run into tablespace permission issues down the line or worse - give the apex user more security permissions than it requires if you go down your intended route which will make exporting and importing a nightmare.

How can Oracle restrict certain data on a table to different users?

Searched the site and doesn't seem to find anyone had asked this question.
We have two accounts accessing the same table on the same schema/database. User_1 account was able to pull back all the records while User_2 account were only able to pull back certain data.
I am aware that Oracle has the ability to restrict table access for different users but I am not aware it can do something like this on the data level.
My question is can Oracle do this and how?
Thanks
You can work with a view.
CREATE OR REPLACE VIEW V_TABLE_FOR_USER_2 AS
SELECT *
FROM THE_TABLE
WHERE {data} = {certain data};
GRANT SELECT, INSERT, DELETE, UPDATE ON THE_TABLE TO USER_1;
GRANT SELECT, INSERT, DELETE, UPDATE ON V_TABLE_FOR_USER_2 TO USER_2;

Make a column a view

To be brief, I won't explain why I want to do this, just what I want to do.
I have two users (which I use as schemas) A and B. Both have a table USERS. Both USERS tables have a columns ID. Every A.USERS.ID is found in B.USERS.ID and every B.USERS.ID is found in A.USERS.ID (I put constraints on that). The only other shared columns between A.USERS and B.USERS is NAME and AGE.
EDIT: To make this clearer... The problem I have is that the values of NAME and AGE are not the same between schemas A and B. For example, user ID 723 in A has A.NAME='John Vincent'. In B, the B.NAME='JJ Vincent'. I want NAME and AGE to be the same at all times. So, I figure that I need to store it in one place and make it visible in two places.
When I let someone query B.USERS, I want B.USERS.NAME and B.USERS.AGE to actually be A.USERS.NAME and A.USERS.AGE. This is the query that I could use if I had permission to query both A and B:
select B.ID, A.NAME, A.AGE from B.USERS join A.USERS on B.USERS.ID=A.USERS.ID
However, I don't want to grant access to A to everyone. I only want to grant access to B (similarly, some people only have access to A and those people are the only ones I want to update the values of NAME and AGE).
I know I can't make just 2 columns be a view. Is there some other trick to make NAME and AGE be a view of A, but have permissions of B? I hope that I've explained enough to make sense. Just trying to avoid writing a dissertation.
You can grant update, insert, delete on B and A to whomever should be able to get to either or. If you want limited view based on your query, you can grant access solely to a view without granting access to the tables.
If you need column specific update access to B, then you can do "column level security" in oracle.
Something like "grant update (column_name) on table_name to user_name", and you'll have granted access to update only "column_name" in that table.

oracle 11g dispaly user created tables

Hi I m new to oracle using 11g exprs edition and familiar with mysql. We can use the below code to display all databases in mysql
show databases;
What is the corresponding command in Oracle. Or how can i display all databases. Also We have
use mydatabase;
to chanage database in mysql. How can i change database in oracle. I tried to display all owners and their tables using the following command
select table_name, owner from all_tables;
It working fine. But when I tried to display tables I have created, by adding a where cluase
select table_name, owner from all_tables where owner='root';
it shows no rows were selected. Why this happens? Also I am facing the same problem with most of the queries when using the where clause. Without where clause it works fine. but when using it, the result is no rows selected for example
select * from all_tab_comments where owner='root';
select constraint_name, constraint_type from user_constraints where table_name='location';
Is there anything special in oracle for where clause or the problem with my query.
Your username is very unlikely to be root; it could however be ROOT, in which case you could do:
select table_name, owner from all_tables where owner='ROOT';
The owner name is case-sensitive, and all objects including users and table names are upper-case by default (unless they're created with double-quotes, which is a bad idea). If you're connected as that user, to see only your own tables you can also do:
select table_name from user_tables;
And there is the dba_tables view which also shows you tables you don't have permissions on, but you can only see that with elevated privileges.
Oracle doesn't have 'databases' in the same sense as other products. You probably means schemas, as the logical grouping of objects. And schemas and users are essentially synonymous.
To get a list of all schemas you can query dba_users (if you have the right privileges), or to get a list of schemas that have objects - as you may have users who only use objects in other schemas - you can do:
select distinct owner from dba_objects;
... or all_objects to again only see things you have permissions for. To see what kind of objects:
select owner, object_type, count(*) from dba_objects group by owner, object_type;
The documentation explains the static data dictionary views which hold all of this information. You won't be able to see all of them though, unless you're connected as a privileged user.
There will be a lot of differences between the two products; you might be better off trying to find a tutorial that works through them rather than using trial and error and trying to understand what's gone wrong at each step. Or at least familiarise yourself with the Oracle documentation so you can research issues.
First, there is going to be a terminology difference when you change platforms. What MySQL calls a "database" is most similar to what Oracle calls a "schema". If you are using Oracle XE, you can only have one database (using Oracle terminology) on the machine. You can have many schemas within that database.
The owner in all_tables is the name of the schema that owns the table. Assuming that you created an Oracle user root (which seems like an odd choice for a database user) and assuming that you did not create a case-sensitive user name in all lower case (which would create a ton of issues down the line), the owner will always be upper-case.
SELECT owner, table_name
FROM all_tables
WHERE owner = 'ROOT'
In Oracle, you do not generally change from one schema to another. You either fully qualify the table name
SELECT *
FROM schema_name.table_name
or you create synonyms (public or private) for objects that you want to reference
CREATE SYNONYM synonym_name
FOR schema_name.table_name;
SELECT *
FROM synonym_name
If you really want to, however, you can change your current schema for name resolution purposes
ALTER SESSION SET current_schema = <<schema name>>
use the view : tabs
select * from tabs;

Resources