oracle 列数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/506176/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Number of columns
提问by DCookie
how do you count the number of columns in a table in oracle?
oracle中如何计算表中的列数?
回答by derobert
SELECT count(*) FROM user_tab_columns WHERE table_name = 'FOO'
should give you the number of columns in foo. You can obtain quite a bit of information from USER_TAB_COLUMNS
and USER_TABLES
(there are also ALL_
and DBA_
variants).
应该给你 foo 中的列数。您可以从USER_TAB_COLUMNS
和USER_TABLES
(也有ALL_
和DBA_
变体)获得相当多的信息。
回答by DCookie
@derobert has a good answer, as long as you are trying to count the columns in a table you own. If you need to count columns in another schema's tables, you'll need to use the all_tab_columns view. One of the additional columns in this view is the table owner. This is also useful when the same tablename exists in multiple schemas. Note that you must have privileges on the tables in order to see them in the all_tab_columns view. The query becomes:
@derobert 有一个很好的答案,只要您尝试计算您拥有的表中的列数。如果您需要计算另一个模式表中的列数,则需要使用 all_tab_columns 视图。此视图中的附加列之一是表所有者。当多个模式中存在相同的表名时,这也很有用。请注意,您必须对表具有权限才能在 all_tab_columns 视图中查看它们。查询变为:
select count(*) from all_tab_columns where owner='BAR' and table_name='FOO';
Note the owner and tablename columns are typically upper case.
请注意 owner 和 tablename 列通常是大写的。
回答by beach
If Oracle supported INFORMATION_SCHEMA.COLUMNS, I'd say use that. But as others have said, use the USER_% views.
如果 Oracle 支持 INFORMATION_SCHEMA.COLUMNS,我会说使用它。但正如其他人所说,使用 USER_% 视图。
For completeness, the following link describes what systems support the SQL-92 Standard. Systems that support INFORMATION_SCHEMA
为完整起见,以下链接描述了哪些系统支持 SQL-92 标准。 支持 INFORMATION_SCHEMA 的系统
回答by Ray K
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;
回答by sanjay Poshiya
Number of column and number of rows in oracle table:
oracle表的列数和行数:
SELECT u.table_name Table_Name,
Count(*) Table_Columns,
u.num_rows Table_Rows
FROM user_tab_columns c,
user_tables u
WHERE u.table_name = c.table_name
GROUP BY u.table_name,
u.num_rows