我很难将存储过程从SQL Server转换为Oracle,以使我们的产品与之兼容.
我有一些查询,根据时间戳返回一些表的最新记录:
SQL Server:
SELECT TOP 1 *
FROM RACEWAY_INPUT_LABO
ORDER BY t_stamp DESC
=> That will returns me the most recent record
但是Oracle:
SELECT *
FROM raceway_input_labo
WHERE rownum <= 1
ORDER BY t_stamp DESC
=> That will returns me the oldest record (probably depending on the index), regardless the ORDER BY
statement!
我以这种方式封装了Oracle查询,以满足我的需求:
SELECT *
FROM
(SELECT *
FROM raceway_input_labo
ORDER BY t_stamp DESC)
WHERE rownum <= 1
而且很有效.但对我来说,这听起来像是一个可怕的黑客攻击,尤其是当我在相关的表中有很多记录时.
实现这一目标的最佳方式是什么?