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.



 



comments
COMMENT USING
PREMIUM SPONSORS
Infragistics is experts in technology and design, and passionate about helping you build highly performant and stylish applications that solve problems, deliver inspiration, and maximize results.
SPONSORED BY
HTML 5 + JQUERY CONTROLS