Skip to Main Content
  • Questions
  • How to find last inserted records from table

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Balakrishna.

Asked: August 03, 2016 - 1:15 am UTC

Last updated: January 30, 2018 - 4:21 pm UTC

Version: 12c

Viewed 10K+ times! This question is

You Asked

HI TOM,


PLEASE EXPLAIN How to find last inserted records from table?
IN ORACLE?

THANKS
BALA

and Connor said...

There is no inbuilt way of knowing - because the rows could be inserted *anywhere* in the table, not necessarily in the "last" block etc.

You could use ORA_ROWSCN to get the last scn for each block on the table as an *approximate* means of seeing when things happened, or the flashback query syntax to get transaction information, but you are limited to the undo_retention settings on your database.

Hope this helps.

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

find out the last inserted row

mahesh, January 30, 2018 - 10:44 am UTC

select * from table_name where rowid=(select max(rowid) from table_name);
Chris Saxon
January 30, 2018 - 4:21 pm UTC

Computer says no:

create table t (
  x int
) partition by list (x) (
  partition p0 values (0),
  partition p1 values (1)
);

insert into t values (1);
commit;
insert into t values (0);
commit;

select * from t where rowid=(select max(rowid) from t); 

X   
  1