How to list all tables that have a matching string in its name - oracle

In Oracle DB, how to list all tables that exist in a schema with the table names having a substring like Student? Say you have a list of tables like College_student, Student_Offer or Student_Dept etc..

SELECT table_name
FROM all_tables
WHERE owner = :owner
AND upper(table_name) LIKE '%STUDENT%';
we upper the name first in the predicate because some people insist on case sensitive object names in Oracle.
I run this with STU vs STUDENT in the LIKE search and see these results -
And since you tagged SQL Developer - you can simply browse a schema using the connection tree and optionally add a filter on the name.

You may query the all_tables table:
SELECT table_name
FROM all_tables
WHERE table_name LIKE '%student%';

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.

how to extract tables attributes like column name , datatype ,nullable for all the tables from the database from oracle pl/sql

Is there any query that can be used to retrive the Tables and its column attributes like column name , datatype, nullable etc for all the tables inside the database
For Oracle Pl/SQL
The Oracle SQL you need would be the following (run as user 'SYS'):
select owner, table_name, column_name, data_type, nullable
from dba_tab_columns;
If you do a desc dba_tab_columns you will get a list of many more columns which may be of interest to you as part of your result set.
You can use a SQL tool (i.e. SQL*Plus) to run this query or you can use PL/SQL to call this query and put the results in PL/SQL variables then print them out via DBMS_OUTPUT.PUT_LINE().
HTH

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;

Extract Table(s) having name in numbers

I am using Oracle developer , my DB have 150+ tables having different namings
i Want to extract all tables having names like
tbl_1234
tbl_22
tbl_45
tbl_719
All tables whose naming convention is like " table name , underscore , number "
Pleaseee help me on this
try following query:
select table_name from user_tables where regexp_like (table_name, '_[0-9]+$');
and you can use, of course, the all_tables or dba_tables view, if you have approriate rights

Query columns names from a table from another user

Sounds pretty easy query the column names from a table, right? Indeed there is a answer to this question How can I get column names from a table in Oracle?
The main issue is that the table belongs to another user. My user is just for integration and I don't have any database privileges.
So I'm able to do some query like: SELECT * FROM anotherUser.THE_TABLE;
But something like SELECT * FROM USER_TAB_COLUMNS return no rows.
Perhaps I can create queries over all_tab_columns, Are there another faster options without procedures?
*It´s a oracle database!
SELECT *
FROM ALL_TAB_COLUMNS
WHERE OWNER='ANOTHERUSER'
AND TABLE_NAME='THE_TABLE';
Should get you there if you have privileges on the table.

Resources