如何在oracle中执行此查询

时间:2010-08-02 16:33:53

标签: sql oracle plsql

请您指导我在Oracle中等效于此查询:

SELECT SQL_CALC_FOUND_ROWS * FROM tableName 

SELECT FOUND_ROWS() as cnt

由于

2 个答案:

答案 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