patternMinor
Finding the number of columns a table has
Viewed 0 times
numberthecolumnshasfindingtable
Problem
How can I find out the number of columns a table has?
I use oracle 10g and I want to develop a J2EE application to count the number of columns of different tables.
I use oracle 10g and I want to develop a J2EE application to count the number of columns of different tables.
Solution
That's what the system catalogs are for:
To get it per table, use a `group by
More details about the system catalogs can be found in the manual:
select count(*)
from all_tab_columns
where owner = 'SOME_USER'
and table_name = 'SOME_TABLE';To get it per table, use a `group by
select table_name, count(*)
from all_tab_columns
where owner = 'SOME_USER'
group by table_name
order by table_name;More details about the system catalogs can be found in the manual:
- ALL_TAB_COLUMNS
- Data Dictionary Views
Code Snippets
select count(*)
from all_tab_columns
where owner = 'SOME_USER'
and table_name = 'SOME_TABLE';select table_name, count(*)
from all_tab_columns
where owner = 'SOME_USER'
group by table_name
order by table_name;Context
StackExchange Database Administrators Q#130572, answer score: 8
Revisions (0)
No revisions yet.