How can I get column names from a table in Oracle

How can I get column names from a table in Oracle

In this blog, we will learn how to get column names from a table in Oracle. Oracle is a database software that uses the Relational database management concept, which means we can store the data in the form of tables.

Table of Contents:

How can I get column names from a table in Oracle?

In Oracle, you can get column names from the table with the below syntax:

Syntax

SELECT column_name 
FROM user_tab_columns 
WHERE table_name = 'YOUR_TABLE_NAME';

Explanation:

  • user_tab_clumns: it is a dictionary view in Oracle, that provides the information about the columns present in a table.
  • table_name = ‘YOUR_TABLE_NAME’: this filters the row where the table name is equal to “YOUR_TABLE_NAME”.

Example to get column names from a table in Oracle

Suppose we have a table Employee, that has some data in it.

Table: Employee

ID Name Dept
1ClarkSales
2JohnHR
3PiyushOps
4OliveIT

Now, If you want to print all the columns from the table, let’s run the below Query:

Query:

SELECT column_name 
FROM all_tab_columns 
WHERE table_name = 'Employee' order by column_name;

Output:

COLUMN_NAME
--------------------------------------------------------------------------------
DEPT
EMPID
NAME

Conclusion

So far in this article, we have learned how we can get column names from a table in Oracle with an example. If you want to excel in your career in SQL, you should visit our SQL course.

About the Author

Data Engineer, Tata Steel Nederland

As a skilled Data Engineer, Sahil excels in SQL, NoSQL databases, Business Intelligence, and database management. He has contributed immensely to projects at companies like Bajaj and Tata. With a strong expertise in data engineering, he has architected numerous solutions for data pipelines, analytics, and software integration, driving insights and innovation.

Intellipaat