How to Get All the Column Names in an Oracle Database


Oracle databases organize tables into owner accounts called schemas. Database users with varying privileges can query the database metadata -- called the "data dictionary" -- to list information including column names, object permissions or object statistics. To obtain column names from tables or views on an Oracle database server, run a short query using the most appropriate data-dictionary object. The USER_TAB_COLS view shows objects owned by the logged-in user, whereas ALL_TAB_COLS shows all objects available to the user given his permissions and DBA_TAB_COLS shows everything in the database irrespective of which user account owns the object.

  • Execute a standard SQL query to return results from the most appropriate system view. A basic query appears in the form:


    Substitute ALL_TAB_COLS or DBA_TAB_COLS as appropriate. The "*" symbol returns all columns in the query.

  • Limit the data returned in the query by replacing "select *" with a more targeted list of columns from the dictionary view. To return only the schema, table name and column name for objects the logged-in account can access, use:

    SELECT owner, table_name, column_name FROM ALL_TAB_COLS;

  • Restrict which objects return by limiting your results with a "where" clause. For example, to return only column names for tables the logged-in user owns and that start with the letter "A," use:


Tips & Warnings

  • Large organizations running an enterprise-grade Oracle server sometimes offer Web-based interfaces to data dictionaries that query all table columns as an anonymous or system user without having to write your own query. Check with a database administrator to see if you have access to such a tool.
  • Oracle also offers ALL_TAB_COLUMNS, USER_TAB_COLUMNS and DBA_TAB_COLUMNS views. These objects differ from those ending in "COLS" by filtering out certain hidden columns. In most cases, you'll get the information you need regardless of which set of views you use.
  • Returning all column names on a very large database with many objects may provide too much information to be useful. Consider narrowing your scope of inquiry with a series of search filters in your SQL "where" clause.
  • To query any data-dictionary object prefixed with DBA, the logged-in account must have "select" rights to those views or have Oracle's SELECT_CATALOG_ROLE assigned. In most cases, the DBA tables must specify the SYS schema prefix, e.g., "SELECT * FROM SYS.DBA_TAB_COLS;" or its equivalent.

Related Searches


  • Photo Credit Justin Sullivan/Getty Images News/Getty Images
Promoted By Zergnet



You May Also Like

  • How to Change a Column Name in SQL

    Microsoft SQL Server allows you to create, edit and delete tables using the SQL syntax. If you want to use SQL to...

  • How to Retrieve Table Names From a Database

    All relational databases that store data are composed of tables. Visually, a table is a group of rows and columns; each column...

  • List of SQL Commands

    SQL stands for Structured Query Language, and it is a language that programmers use to interact with databases through many programs such...

  • SQL Server Vs. Oracle Data Types

    While designing and defining tables in databases, it is important to find out the data type for each column in the data...

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!