Blog

Number of columns in Table

Posted by Shankar M Blogs | SQL Dec 12, 2012
To know the number of columns in a table with out using describe statement in Oracle SQL
In this blog, I have discussed how to calculate the number of columns in a table without using the
describe statement.

To exemplify this, we will create a table and select the number of columns from the
user_tab_columns view for the current user.

Table Script :

CREATE TABLE EMP
(
  EMPNO     NUMBER(4),
  ENAME     VARCHAR2(10),
  JOB       VARCHAR2(9),
  MGR       NUMBER(4),
  HIREDATE  DATE,
  SAL       NUMBER(7,2),
  COMM      NUMBER(7,2),
  DEPTNO    NUMBER(2)
)

USER_TAB_COLUMS :
    This data dictionary view describes the columns of the tables,views etc for the current user.

Query :
 
 SELECT COUNT(*)
 FROM USER_TAB_COLUMNS
 WHERE table_name = 'EMP';

Which results to

COUNT(*)

----------

8

Summary :

 In this blog, I have discussed how to count the number of columns in the table for the current user.



 



COMMENT USING
PREMIUM SPONSORS
Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.
Employers - Post Free Jobs
SPONSORED BY
  • MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.