请您指导我在Oracle中等效于此查询:
SELECT SQL_CALC_FOUND_ROWS * FROM tableName
SELECT FOUND_ROWS() as cnt
由于
答案 0 :(得分:3)
对于Oracle 9i +,请使用:
SELECT COUNT(*) over () found_rows,
t.*
FROM TABLE t
Be aware that it is faster to run separate queries than to use SQL_CALC_ROUND_ROWS in MySQL
答案 1 :(得分:1)
查询从tableName
检索所有行,然后检索tableName
中的行数。使用SQL_CALC_FOUND_ROWS
执行此操作只是一种性能优化:它可以避免您进行两次查询。
如果性能不是问题,Oracle的等效项将是:
SELECT * FROM tableName
SELECT count(*) from tableName
如果您能够重写客户端,则可以在一个查询中执行这两项操作:
SELECT *
, (SELECT count(*) from tableName) as totalRows
FROM tableName