oracle 以 KB 为单位确定 SQL 结果集的大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1410881/
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
Determine the size of a SQL result set in KB
提问by shermy
I am hoping to find how I can get the kb size of a result set in OracleDB. I am not an sysadmin, but often run queries that return over 100k rows and I would need to find a way to determine what is the total kb size. thank you
我希望找到如何在 OracleDB 中获取结果集的 kb 大小。我不是系统管理员,但经常运行返回超过 100k 行的查询,我需要找到一种方法来确定总 kb 大小。谢谢你
回答by jva
In SQL*Plus:
在 SQL*Plus 中:
SET AUTOTRACE ON
SELECT *
FROM emp
WHERE rownum <= 100;
27 recursive calls
0 db block gets
19 consistent gets
4 physical reads
0 redo size
**11451 bytes sent via SQL*Net to client**
314 bytes received via SQL*Net from client
8 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
100 rows processed
To use AUTOTRACE requires the PLUSTRACE role, which is not granted by default. Find out more.
要使用 AUTOTRACE 需要 PLUSTRACE 角色,默认情况下不会授予该角色。了解更多。
回答by paxdiablo
Generally, you would replace your column list with a count(*)
to return the row count.
通常,您可以用 a 替换列列表count(*)
以返回行数。
I'm not sure how well that would work on really complicated queries with many joins and such but, for simpler queries, it should be fine. Replace:
我不确定这对于具有许多连接等的真正复杂查询的效果如何,但是对于更简单的查询,它应该没问题。代替:
select a,b,c from t where a > 7;
with
和
select count(*) from t where a > 7;
That will give you the row count before you run the real query. Just keep in mind there's a chance the data may change between your count query and real query (hopefully not too much). Knowledge of the data properties will allow you to approximate kilobytes from row count.
这将在您运行真正的查询之前为您提供行数。请记住,您的计数查询和实际查询之间的数据可能会发生变化(希望不会太多)。了解数据属性将使您能够从行数中估算出千字节数。