如何使用SQL计算表中的列数? [重复]

时间:2022-03-26 09:27:04

This question already has an answer here:

这个问题在这里已有答案:

How to count the number of columns in a table using SQL?

如何使用SQL计算表中的列数?

I am using Oracle 11g

我正在使用Oracle 11g

Please help. t.

请帮忙。吨。

3 个解决方案

#1


28  

select count(*) 
from user_tab_columns
where table_name='MYTABLE' --use upper case

#2


5  

Old question - but I recently needed this along with the row count... here is a query for both - sorted by row count desc:

老问题 - 但我最近需要这个以及行计数...这里是两个查询 - 按行数desc排序:

select t.owner, t.table_name, t.num_rows, count(*)
from all_tables t left join all_tab_columns c on t.table_name = c.table_name
where num_rows is not null
group by t.owner, t.table_name, t.num_rows
order by t.num_rows desc;

#3


4  

Maybe something like this:

也许是这样的:

SELECT count(*) FROM user_tab_columns WHERE table_name = 'FOO'

this will count number of columns in a the table FOO

这将计算表FOO中的列数

You can also just

你也可以

select count(*) from all_tab_columns where owner='BAR' and table_name='FOO';

where the owner is schema and note that Table Names are upper case

所有者是架构,并注意表名称是大写

#1


28  

select count(*) 
from user_tab_columns
where table_name='MYTABLE' --use upper case

#2


5  

Old question - but I recently needed this along with the row count... here is a query for both - sorted by row count desc:

老问题 - 但我最近需要这个以及行计数...这里是两个查询 - 按行数desc排序:

select t.owner, t.table_name, t.num_rows, count(*)
from all_tables t left join all_tab_columns c on t.table_name = c.table_name
where num_rows is not null
group by t.owner, t.table_name, t.num_rows
order by t.num_rows desc;

#3


4  

Maybe something like this:

也许是这样的:

SELECT count(*) FROM user_tab_columns WHERE table_name = 'FOO'

this will count number of columns in a the table FOO

这将计算表FOO中的列数

You can also just

你也可以

select count(*) from all_tab_columns where owner='BAR' and table_name='FOO';

where the owner is schema and note that Table Names are upper case

所有者是架构,并注意表名称是大写