oracle 11g dispaly user created tables - oracle

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;

Related

Identify system table in Oracle 11

ALL,
Is there a way to identify the system tables in Oracle 11g?
If I call SQLTables() API, I will get a list of all tables available. What I'd like is to identify what table is internal Oracle and which one is user-made.
I'm connecting with the system account. (a dba one).
TIA!
Query e.g. DBA_TABLES (which means that you have access to all tables in that database), using the OWNER column name as filter. For example:
select owner, table_name
from dba_tables
where owner in ('SYS', 'SYSTEM');
For more owners, query DBA_USERS:
select * from dba_users;
and include any you want into the first query.

ORA-00942: Table or View not exist connecting with another user

in Oracle SQL developer I got error ORA-00942: Table or View not exist connecting with another user when I do the following:
CREATE USER marta IDENTIFIED BY 'marta';
GRANT SELECT, INSERT ON myTable TO marta;
so then, executing:
CONNECT marta/marta;
INSERT INTO myTable VALUES ('1', 'foo', bar');
got the ORA-00942...
Obviusly, If I use system user I can insert row with no issues.
I searched other answers but I couldnt solve this... what is wrong
Obviusly, If I use system user I can insert row with no issues.
Uh-oh. There's nothing obvious about that. The SYSTEM user should not own a table called MY_TABLE (or whatever application table that is actually named). The SYSTEM user is part of the Oracle database, its schema is governed by Oracle and using it for our own application objects is really bad practice.
But it seems you have created a table in that schema and user MARTA can't see it. That's standard. By default users can only see their own objects. They can only see objects in other schemas if the object's owner (or a power user) grants privileges on that object to the other user.
So, as SYSTEM
grant select on my_table to marta;
Then, as MARTA
select * from system.my_table;
To avoid prefixing the owning schema MARTA can create a synonym:
create or replace synonym my_table for system.my_table;
select * from my_table;
But really, you need to stop using SYSTEM for your own tables.

What Oracle privilege is to be granted to a role so it allows users to see tables in Oracle SQL Developer schema

Using Oracle 12c, I have a role which I have granted basic CRUD operations to using Oracle SQL Developer. The problem is, users of the group can not see the list of tables in Oracle SQL Developer. All they see is the branch that shows a tables node but there is no plus sign to expand and see the tables for the one schema they need to work with. What other privilege needs to be granted to the group so they can see all the table nodes for their schema when using Oracle SQL Developer? Thanks in advance.
If I understood you correctly, you
created a role
granted certain privileges to that role
created bunch of users
granted role (from step 1) to those users
but they still don't see anything.
If that's so, they won't see anything regardless of what you grant - it is because they don't have those objects in theirs schemas.
What you (or they) should/could do is to precede table name with owner name while selecting data from those tables. Suppose that there's a table named EMPLOYEE and your users want to select data from it - they should run select * from robertcode.employee (presuming that user robertcode owns that table)
Although it works, users won't be happy because they don't know table names. Therefore, create a script which they will run in their schemas - that script will create synonyms to your tables.
In order to do that, write query which will create query:
SQL> select 'create synonym ' || table_name || ' for ' || table_name ||';'
2 from user_tables;
'CREATESYNONYM'||TABLE_NAME||'FOR'||TABLE_NAME||';'
--------------------------------------------------------------------------------
create synonym EMP for EMP;
create synonym BONUS for BONUS;
create synonym SALGRADE for SALGRADE;
create synonym DEPT for DEPT;
Copy/paste all those create synonym ... statements into an e-mail message and let them create synonyms for themselves.
They still won't see anything under the Tables node (because those users don't have tables (until they create them in their own schema), but will see something in Synonyms.

Oracle tables show "not_found?.TABLENAME

I am using Oracle. A legacy script created our table structure.
When I try to select from, say, tableA, sql developer very helpfully finds the table as I type. But instead of filling in a valid user it shows me (eg)
SELECT * FROM not_found?.tableA
I'm guessing the script pulled the user incorrectly, but the table seems to actually exist (or it wouldn't fill in the user, n'est ce pas?). Does anyone know WHERE THE HECK IT IS?
Use this to find the schema in which the table is:
select owner from all_tables where table_name = 'TABLEA';

In Oracle, how to list all the tables in *my* schema that *I* created (without having DBA privileges)

I'm an Oracle11XE user with privileges to create and drop tables and procedures. I create a few tables, then while visiting the restroom, MIB zap me with a memory wipe (I foolishly looked into the light). Returning to sit at my workstation, I realize I need to query the database with my regular user privs, and figure out what that table or tables I created and the DBA has mysteriously gone missing.
You can use USER_TABLES view to get all the tables currently in your schema:
select table_name
from user_tables
If, additionally, you are interested in knowing when the tables were created, then you can use the USER_OBJECTS view where OBJECT_TYPE = 'TABLE'. That view includes the CREATED column.
select object_name, created
from user_objects
where object_type = 'TABLE'

Resources