简体   繁体   English

Oracle SQL / Java:从查询中获取返回数据集的大小

[英]Oracle SQL / Java : Get the size of returned dataset from a query

Is it possible to know the size of a dataset returned by a SQL statement in bytes 是否可能知道SQL语句返回的数据集的大小(以字节为单位)

It would be nice if from the query itself I can get the size of the data. 如果从查询本身可以得到数据的大小,那将是很好的。 I found something like using SQL Plus, but I could not use that in my Java codes. 我找到了类似使用SQL Plus的内容,但是无法在Java代码中使用它。

I know there maybe ways in doing it Java, can anyone guide me on how can I do that. 我知道有可能使用Java进行编程,有人可以指导我如何做到这一点。

Thanks in advance. 提前致谢。

Docs : 文件

A ResultSet object maintains a cursor pointing to its current row of data. ResultSet对象维护一个游标,该游标指向其当前数据行。 Initially the cursor is positioned before the first row. 最初,光标位于第一行之前。 The next method moves the cursor to the next row, and because it returns false when there are no more rows in the ResultSet object, it can be used in a while loop to iterate through the result set. next方法将光标移动到下一行,并且由于当ResultSet对象中没有更多行时它返回false,因此可以在while循环中使用它来迭代结果集。

ResultSet is not a collection, it is merely an abstraction of the cursor that is being used to get the data in a row-wise manner. ResultSet不是集合,它只是用于以行方式获取数据的游标的抽象。

So, what exactly do need? 那么,到底需要什么呢? The amount of memory needed to store the result? 存储结果所需的内存量? The size of the data in the database? 数据库中数据的大小? ...? ...? Why would it be nice? 为什么会很好?

You can always do SELECT COUNT(*) FROM and using a certain average size of row estimate the result size... Instead of using the SELECT COUNT(*) you can use a more convoluted way: go to the last element ResultSet.last() and get the row number: ResultSet.getRow() . 您始终可以执行SELECT COUNT(*) FROM并使用特定的行平均大小来估计结果大小...而不是使用SELECT COUNT(*)您可以使用更复杂的方式:转到最后一个元素ResultSet.last()并获取行号: ResultSet.getRow()

I know there maybe ways in doing it Java, can anyone guide me on how can I do that. 我知道有可能使用Java进行编程,有人可以指导我如何做到这一点。

I'm pretty sure that the answer is that there is no easy way to do this. 我很确定答案是没有简单的方法可以做到这一点。

The JDBC abstraction hides database driver implementation details from you, and the number of bytes used to encode the results set is very driver specific. JDBC抽象对您隐藏了数据库驱动程序的实现细节,并且用于编码结果集的字节数与驱动程序有关。

Once the resultset is materialized into the Java heap, it is theoretically possible to find out its size. 一旦将结果集具体化到Java堆中,理论上就有可能找出其大小。 But in practice, you have to traverse every heap node in the resultset ... which is not a simple problem. 但是实际上,您必须遍历结果集中的每个堆节点……这不是一个简单的问题。


COUNT() method give us the number of rows from the query, is there a way to convert it into bytes? COUNT()方法为我们提供了查询的行数,是否可以将其转换为字节?

In a word, no. 一言以蔽之。 Not even in theory. 甚至在理论上也没有。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM