如何获取Oracle表的最后一行 [英] How to get the last row of an Oracle a table

查看:208
本文介绍了如何获取Oracle表的最后一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得最后一行,我将其插入到Oracle 11g Express数据库中的表中. 我该怎么办?

I want to get the last row, which I inserted into a table in an Oracle 11g Express database. How can I do this?

推荐答案

表中没有最后"行之类的东西,因为Oracle表没有顺序概念.

There is no such thing as the "last" row in a table, as an Oracle table has no concept of order.

但是,假设您要查找最后插入的主键并且该主键是一个递增数字,则可以执行以下操作:

However, assuming that you wanted to find the last inserted primary key and that this primary key is an incrementing number, you could do something like this:

select *
  from ( select a.*, max(pk) over () as max_pk
           from my_table a
                )
 where pk = max_pk

如果具有创建每一行的日期,则该日期将变为(如果该列名为created:

If you have the date that each row was created this would become, if the column is named created:

select *
  from ( select a.*, max(created) over () as max_created
           from my_table a
                )
 where created = max_created

或者,您可以使用汇总查询,例如:

Alternatively, you can use an aggregate query, for example:

select *
  from my_table
 where pk = ( select max(pk) from my_table )

这里有一些 SQL小提琴来演示.

这篇关于如何获取Oracle表的最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆