How to find all tables in Oracle that have specific columns?
How to find all tables in Oracle that have specific columns?
27617-Jul-2023
Updated on 18-Jul-2023
Home / DeveloperSection / Forums / How to find all tables in Oracle that have specific columns?
How to find all tables in Oracle that have specific columns?
Aryan Kumar
18-Jul-2023To find all tables in Oracle that have specific columns, you can use the following SQL query:
SQL
This query will first select all tables from the
all_tables
view. Theall_tables
view is a data dictionary view that contains information about all of the tables in the database.The next part of the query uses the
EXISTS
clause to check if each table in theall_tables
view has the specified columns. TheEXISTS
clause takes a subquery as its argument. The subquery in this case selects all columns from theall_tab_cols
view where the table name is equal to the table name in theall_tables
view and the column name is equal to one of the specified columns.If the subquery returns any rows, then the
EXISTS
clause will returnTRUE
. This means that the table in theall_tables
view has the specified columns.The final part of the query selects the
table_name
column from theall_tables
view for all tables that have the specified columns.To run this query, you will need to connect to the Oracle database using a tool like SQLPlus. Once you are connected, you can run the query by typing it into the SQLPlus prompt.
For example, to run the query above, you would type the following into the SQL*Plus prompt:
SQL
This would return a list of all tables in the database that have the specified columns.