Ask the Expert

Calculating number of columns

How do I calculate the number of columns in a table without using the "DESCRIBE tablename"?

    Requires Free Membership to View

For this one, you can use one of the catalog views, ALL_TAB_COLUMNS. Each row in this view represents a column of a table or view to which you have rights. To illustrate, we'll create a dummy table, and then select a count from the ALL_TAB_COLUMNS view.
 
create table "ATE"."DUMMY_TABLE"
( dummycol1 numeric(10),
  dummycol2 varchar(4),
  dummycol3 date
);

select count(*) 
  from all_tab_columns 
  where owner = 'ATE' 
    and table_name = 'DUMMY_TABLE';

Here is the result of the query.

  COUNT(*)
----------
         3

This was first published in November 2003

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: