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.