我想在一个oracle中创建一个查询,该查询将显示我制作的表中的最后一个条目,我尝试了最大和最大日期,但是在最大之后,查询不准确,到期日期显示了所有日期,将感谢您的帮助)
日期之后
select seal_number
from SEC_OBJECT_SEALING
where SEALING_OBJECT = :P26_OBJECT_UNPLUG
and (to_date(data ,'dd.mm.yyyy hh24:mi:ss') =
(select max(to_date(data ,'dd.mm.yyyy hh24:mi:ss')) from SEC_OBJECT_SEALING)
通过最大
select seal_number
from SEC_OBJECT_SEALING
where SEALING_OBJECT = :P26_OBJECT_UNPLUG
and id = (select max(id) from SEC_OBJECT_SEALING)
答案 0 :(得分:2)
在Oracle 12+中,使用fetch
:
select seal_number
from SEC_OBJECT_SEALING
where SEALING_OBJECT = :P26_OBJECT_UNPLUG
order by data desc
fetch first 1 row only;
在早期版本中,使用子查询:
select sos.*
from (select seal_number
from SEC_OBJECT_SEALING
where SEALING_OBJECT = :P26_OBJECT_UNPLUG
order by data desc
) sos
where rownum = 1;