Как найти таблицу в оракл

In this tutorial I will show you 3 quick ways to find a table by a name using Oracle SQL Developer.

Option 1: Filter

First option is to use object filter. Select connection and click filter icon.

Then provide table text that should be part of table name. Don’t forget about «%» on both sides of string.

Oracle SQL Developer will show you only tables with names fitting this criteria.

To clear filter right click on connection and select Clear Filter.

Option 2: Schema Browser

Second option, most convenient in my opinion, is with use of Schema Browser. To open it right click on the object explorer and choose Schema Browser option:

It will show new tab like below. Use field on the bottom to type in the word you are searching for:

Option 3: Find DB Object

The last option is with the use of Find Database Object feature. To open it do one of the following:

  1. click binocular icon from the toolbar,
  2. right click object explorer and choose Find DB Object option,
  3. go to View main menu and choose Find DB Object option.

Search tab will be opened in the left pane. Type in text you are searching for with «%» on both sides of it and press enter. It will open new tab in main window with the results. You can navigate to table details by clicking its name.

Bonus: Dataedo

Another option is to share schema design and documentation in searchable HTML documents using Dataedo.

With Dataedo you can:

  1. Allow everyone, without access to database or technical knowledge), to discover and search schema
  2. Describe each table and column, with description and a number of custom fields
  3. Explain table relationships, even if they do not have foreign key constraints in a database, and then visualize them with diagrams
  4. Provide meaningful aliases for tables and columns (note on the screen below that one table was found that did not had the keyword in the name, but in alias)
  5. Search and discover tables by names, column names and their aliases
  6. and so much more

Try it yourself.

The data you want is in the «cols» meta-data table:

SELECT * FROM COLS WHERE COLUMN_NAME = 'id'

This one will give you a list of tables that have all of the columns you want:

select distinct
  C1.TABLE_NAME
from
  cols c1
  inner join
  cols c2
  on C1.TABLE_NAME = C2.TABLE_NAME
  inner join
  cols c3
  on C2.TABLE_NAME = C3.TABLE_NAME
  inner join
  cols c4
  on C3.TABLE_NAME = C4.TABLE_NAME  
  inner join
  tab t
  on T.TNAME = C1.TABLE_NAME
where T.TABTYPE = 'TABLE' --could be 'VIEW' if you wanted
  and upper(C1.COLUMN_NAME) like upper('%id%')
  and upper(C2.COLUMN_NAME) like upper('%fname%')
  and upper(C3.COLUMN_NAME) like upper('%lname%')
  and upper(C4.COLUMN_NAME) like upper('%address%')  

To do this in a different schema, just specify the schema in front of the table, as in

SELECT * FROM SCHEMA1.COLS WHERE COLUMN_NAME LIKE '%ID%';

If you want to combine the searches of many schemas into one output result, then you could do this:

SELECT DISTINCT
  'SCHEMA1' AS SCHEMA_NAME
 ,TABLE_NAME
FROM SCHEMA1.COLS
WHERE COLUMN_NAME LIKE '%ID%'
UNION
SELECT DISTINCT
  'SCHEMA2' AS SCHEMA_NAME
 ,TABLE_NAME
FROM SCHEMA2.COLS
WHERE COLUMN_NAME LIKE '%ID%'

A new feature available in SQLcl( which is a free command line interface for Oracle Database) is

Tables alias.

Here are few examples showing the usage and additional aspects of the feature. First, connect to a sql command line (sql.exe in windows) session. It is recommended to enter this sqlcl specific command before running any other commands or queries which display data.

SQL> set sqlformat ansiconsole     -- resizes the columns to the width of the 
                                   -- data to save space 

SQL> tables

TABLES
-----------
REGIONS
LOCATIONS
DEPARTMENTS
JOBS
EMPLOYEES
JOB_HISTORY
..

To know what the tables alias is referring to, you may simply use alias list <alias>

SQL> alias list tables
tables - tables <schema> - show tables from schema
--------------------------------------------------

 select table_name "TABLES" from user_tables

You don’t have to define this alias as it comes by default under SQLcl. If you want to list tables from a specific schema, using a new user-defined alias and passing schema name as a bind argument with only a set of columns being displayed, you may do so using

SQL> alias tables_schema = select owner, table_name, last_analyzed from all_tables where owner = :ownr;

Thereafter you may simply pass schema name as an argument

SQL> tables_schema HR

OWNER   TABLE_NAME               LAST_ANALYZED
HR      DUMMY1                   18-10-18
HR      YOURTAB2                 16-11-18
HR      YOURTABLE                01-12-18
HR      ID_TABLE                 05-12-18
HR      REGIONS                  26-05-18
HR      LOCATIONS                26-05-18
HR      DEPARTMENTS              26-05-18
HR      JOBS                     26-05-18
HR      EMPLOYEES                12-10-18
..
..

A more sophisticated pre-defined alias is known as Tables2, which displays several other columns.

SQL> tables2

Tables
======
TABLE_NAME                 NUM_ROWS   BLOCKS   UNFORMATTED_SIZE COMPRESSION     INDEX_COUNT   CONSTRAINT_COUNT   PART_COUNT LAST_ANALYZED
AN_IP_TABLE                       0        0                  0 Disabled                  0                  0            0 > Month
PARTTABLE                         0        0                  0                           1                  0            1 > Month
TST2                              0        0                  0 Disabled                  0                  0            0 > Month
TST3                              0        0                  0 Disabled                  0                  0            0 > Month
MANAGE_EMPLYEE                    0        0                  0 Disabled                  0                  0            0 > Month
PRODUCT                           0        0                  0 Disabled                  0                  0            0 > Month
ALL_TAB_X78EHRYFK                 0        0                  0 Disabled                  0                  0            0 > Month
TBW                               0        0                  0 Disabled                  0                  0            0 > Month
DEPT                              0        0                  0 Disabled                  0                  0            0 > Month

To know what query it runs in the background, enter

alias list tables2

This will show you a slightly more complex query along with predefined column definitions commonly used in SQL*Plus.

Jeff Smith explains more about aliases here

Do you need to get a list of all the tables in your SQL database?

Learn how to do this in several different database vendors in this guide.

Sometimes you need to get a list of tables from your database. This could be to help with testing, to see what tables exist before you create a table or remove one, or some other reason.

If you’ve forgotten the name of a specific table, or forgotten how to spell a table (was it plural or singular? One word or two with an underscore?), then you can use these queries to show all tables in your database.

Each database vendor has a different way of showing tables. Sometimes there is a command, others have a SELECT query from the data dictionary.

Let’s take a look at a few ways in each database.

Show Tables in Oracle SQL

Oracle has several different built-in views that you can query to find the data you need. You can query any of these views to list all tables in Oracle.

You might not have the privileges to view each of these views, so if one query doesn’t work, try another one.

User Owned Tables

To see tables owned by the currently logged-in user, you can query the user_tables view.

SELECT table_name
FROM user_tables
ORDER BY table_name ASC;

This only shows tables owned by the current user. It doesn’t include tables owned by other users that the current user can see.

User Accessible Tables

To see all tables that the current user can access, you can query the all_tables view.

SELECT table_name
FROM all_tables
ORDER BY table_name ASC;

You can add the owner column to your view to see who owns the table:

SELECT table_name, owner
FROM all_tables
ORDER BY table_name ASC;

This may show you a lot of results, including a lot of system tables. You can add a WHERE clause for the owner field to filter on the owner.

All Database Tables

If you want to list all tables in the Oracle database, you can query the dba_tables view.

SELECT table_name
FROM dba_tables
ORDER BY table_name ASC;

This view (and all others starting with dba_) are meant for database administrators. If you don’t have admin rights, you’ll get this error:

ORA-00942: table or view does not exist.

In order to see this view, you’ll need either of these privileges:

  • the dba_tables view
  • the SELECT ANY DICTIONARY privilege
  • the SELECT_CATALOG_ROLE role

If you’re not sure if the object you’re querying is a table or a view, you can also query the dba_views, all_views, or user_views objects.

These queries perform a UNION ALL to show you a list of all tables and views in the Oracle database.

DBA_TABLES and DBA_VIEWS

SELECT 'Table' AS object_type, owner, table_name
FROM dba_tables
UNION ALL
SELECT 'View', owner, view_name
FROM dba_views;

ALL_TABLES and ALL_VIEWS

SELECT 'Table' AS object_type, owner, table_name
FROM all_tables
UNION ALL
SELECT 'View', owner, view_name
FROM all_views;

USER_TABLES and USER_VIEWS

SELECT 'Table' AS object_type, table_name
FROM user_tables
UNION ALL
SELECT 'View', view_name
FROM user_views;

Show Tables in SQL Server

There are a few ways to list tables in SQL Server.

All Tables and Views

The easiest way to find all tables in SQL is to query the INFORMATION_SCHEMA views.

You do this by specifying the information schema, then the “tables” view.

Here’s an example.

SELECT table_name, table_schema, table_type
FROM information_schema.tables
ORDER BY table_name ASC;

This will show the name of the table, which schema it belongs to, and the type.

The type will either be “BASE TABLE” for tables or “VIEW” for views.

All Tables Only

To see a list of only tables and not views, you can filter on the table_type column.

SELECT table_name, table_schema
FROM information_schema.tables
WHERE table_type = 'BASE TABLE'
ORDER BY table_name ASC;

SQL Server 2000

If you’re running SQL Server 2005 you can use the information_schema method above. If you’re on 2000 or earlier, then you’ll need to use a different method.

You can query the SYSOBJECTS view to find all of the tables in the database. This shows all objects, so to filter it to tables we can filter on the xtype column equals the value of “U”, which represents a user table.

Here’s the query:

SELECT *
FROM sysobjects
WHERE xtype = 'U'
ORDER BY name ASC;

Show Tables in MySQL

There are a few ways to list tables in MySQL.

Show Tables Command

You can run the command SHOW TABLES once you have logged on to a database to see all tables.

SHOW TABLES;

The output will show a list of table names, and that’s all.

Show Table Type

You can use the optional FULL modifier which shows the table type as well.

SHOW FULL TABLES;

This will show the table name and the table type, which is either VIEW or BASE TABLE.

Show Tables in Another Database

You can use this command to see a list of tables in another database as well.

SHOW TABLES FROM database_name;

Show Tables Matching a Pattern

When selecting from a view in other databases, you can use LIKE to filter the tables that match a certain string.

You can do the same with the SHOW TABLES command:

SHOW TABLES LIKE string;

To see all tables that include the letter “user”, you can run this command.

SHOW TABLES LIKE '%user%';

Show Tables in PostgreSQL

There are a couple of ways to view a list of tables in PostgreSQL.

Show Tables

If you’re using a command line, you can use the dt command to display all tables:

dt

This won’t work in an IDE, but there is another method for that.

Show Tables and Descriptions

If you’re using a command line, you can use the dt command to display all tables plus the table descriptions:

dt+

As above, there is another method if you’re not using the command line.

Select from Catalog

If you want another method, or if you’re using an IDE and can’t use dt, then you can select from the pg_catalog schema.

Here’s an example:

SELECT tablename, schemaname, tableowner
FROM pg_catalog.pg_tables
WHERE schemaname != 'pg_catalog'
AND schemaname != 'information_schema'
ORDER BY tablename ASC;

This will show you information for all tables in the database. The WHERE clause filters out system tables, but you can omit the WHERE clause and see those tables if you need to.

Conclusion

There are several ways for each vendor to see a list of tables in the database. Some are inbuilt commands and others are selecting from database views. Showing a list of databases is done in a similar way.

Improve Article

Save Article

Like Article

  • Read
  • Discuss
  • Improve Article

    Save Article

    Like Article

    In this article, we will discuss all the methods to list all tables in the oracle SQL Database.

    We have three types of a subset of tables available to use as identifiers which in turn help us to sort the required table names. Here, are the following types of table identifiers in the Oracle SQL Database.

    1. DBA_tables:

    If the user is SYSTEM or has access to dba_tables data dictionary view, then use the given below query:

    Query:

    SELECT owner, table_name FROM dba_tables;

    This query returns the following list of tables that contain all the tables that are there in the entire database.

    Output:

    2. All_tables:

    If the user does not have access or privilege to view the dba_tables it can still get a list of all the tables that it has access to using the following SQL query. This SQL query gives the list of tables that can be accessed by the user along with its owner.

    Query:

    SELECT owner, table_name FROM all_tables;

    This query returns the following list of tables that contain all the tables that the user has access to in the entire database.

    Output:

    3. User_tables

    If the user wants the list of all tables owned/created by him only, then use the following SQL query to get a list of tables. The following query does not return the name of the owner as it is the user itself for all the tables.

    Query:

    SELECT table_name FROM user_tables;

    This query returns the following list of tables that contain all the tables owned by the user in the entire database.

    Output:

    Last Updated :
    28 Oct, 2021

    Like Article

    Save Article

    Понравилась статья? Поделить с друзьями:
  • Как найти ремонтный размер
  • Dead by daylight как найти люк
  • Как найти летящий самолет онлайн
  • Как составить план теодолитного хода
  • Как найти номер двигателя пежо 206