【问题标题】:Creating a Query to find the number of rows (count) by the tables of a schema in real time创建查询以通过模式的表实时查找行数(计数)
【发布时间】:2017-01-31 16:14:22
【问题描述】:

我想在 ORACLE-SQL Developer 中创建一个查询,实时返回查询中指定的表及其计数/行数。

理想的输出应该是这样的;

| Schema.Table | Count |
|  abc.123     |  1000 |    
|  def.345     |  1223 |      etc.

到目前为止,我有一个使用 dba_tables 的非常基本的查询;

SELECT OWNER ||'.'|| table_name as "Schema.Tablename", 
       num_rows as "Number of Rows"  
  FROM dba_tables 
WHERE
   table_name = '123' and OWNER = 'abc'
or table_name = '345' and OWNER = 'def'

但是,我希望能够实时获得查询计数,因此我不想使用 dba_tables 或 num_rows。

有人对这项任务有任何提示或建议吗?

【问题讨论】:

标签: sql database count oracle-sqldeveloper


【解决方案1】:

如果您明确列出表,那么只需使用表编写查询:

SELECT 'abc.123' as table_name, count(*) as cnt
FROM abc.123
UNION ALL
SELECT 'def.345' as table_name, count(*) as cnt
FROM def.345;

这比 PL/SQL 循环和动态 SQL 简单得多。

【讨论】:

  • 有没有更有效的方法来做到这一点?我已经尝试过了,但是我需要指定的表数量太长了,服务器冻结了
  • @MarkX 。 . .阅读所有表格需要时间。这就是为什么有更快的近似方法。
猜你喜欢
  • 2016-11-22
  • 2020-03-28
  • 1970-01-01
  • 1970-01-01
  • 2020-12-30
  • 1970-01-01
  • 2012-02-28
  • 2011-09-02
  • 2023-03-18
相关资源
最近更新 更多