【发布时间】:2012-04-22 11:40:48
【问题描述】:
如何使用 SQL 统计表中的列数?
我正在使用 Oracle 11g
请帮忙。 t.
【问题讨论】:
如何使用 SQL 统计表中的列数?
我正在使用 Oracle 11g
请帮忙。 t.
【问题讨论】:
select count(*)
from user_tab_columns
where table_name='MYTABLE' --use upper case
您可以使用 lower 函数代替大写。 前任: select count(*) from user_tab_columns where lower(table_name)='table_name';
【讨论】:
可能是这样的:
SELECT count(*) FROM user_tab_columns WHERE table_name = 'FOO'
这将计算表 FOO 中的列数
你也可以
select count(*) from all_tab_columns where owner='BAR' and table_name='FOO';
所有者是架构,注意表名是大写的
【讨论】:
老问题 - 但我最近需要这个以及行数......这是两者的查询 - 按行数 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;
【讨论】: