Last Record [message #651916] |
Fri, 27 May 2016 07:27 |
|
Satheesh.A
Messages: 9 Registered: May 2016 Location: Chennai
|
Junior Member |
|
|
How to find last inserted records from table using oracle 11g?
|
|
|
Re: Last Record [message #651917 is a reply to message #651916] |
Fri, 27 May 2016 07:29 |
John Watson
Messages: 8938 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
That would depend on how (or if) you record the time of insertion. If you do not record this, there is no precise method.
By the way, you will not get a job with Oracle if you say "record" when you mean "row".
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Last Record [message #651959 is a reply to message #651929] |
Sat, 28 May 2016 06:37 |
Solomon Yakobson
Messages: 3275 Registered: January 2010 Location: Connecticut, USA
|
Senior Member |
|
|
Michel Cadot wrote on Fri, 27 May 2016 15:59
Other method: create your table with ROWDEPENDENCIES property.
No, it will not allow to find last row. ALL rows affected by ALL statements withing transaction will have same ORA_ROWSCN.
SQL> select l,ora_rowscn from tbl;
L ORA_ROWSCN
---------- ----------
1 42951355
2 42951355
3 42951355
4 42951355
5 42951355
6 42951355
7 42951355
8 42951355
9 42951355
10 42951355
10 rows selected.
SQL> update tbl set l = l where l = 5;
1 row updated.
SQL> select l,ora_rowscn from tbl;
L ORA_ROWSCN
---------- ----------
1 42951355
2 42951355
3 42951355
4 42951355
5
6 42951355
7 42951355
8 42951355
9 42951355
10 42951355
10 rows selected.
SQL> update tbl set l = l where l = 3;
1 row updated.
SQL> select l,ora_rowscn from tbl;
L ORA_ROWSCN
---------- ----------
1 42951355
2 42951355
3
4 42951355
5
6 42951355
7 42951355
8 42951355
9 42951355
10 42951355
10 rows selected.
SQL> insert into tbl values(11);
1 row created.
SQL> select l,ora_rowscn from tbl;
L ORA_ROWSCN
---------- ----------
1 42951355
2 42951355
3
4 42951355
5
6 42951355
7 42951355
8 42951355
9 42951355
10 42951355
11
11 rows selected.
SQL> commit;
Commit complete.
SQL> select l,ora_rowscn from tbl;
L ORA_ROWSCN
---------- ----------
1 42951355
2 42951355
3 42951706 <---
4 42951355
5 42951706 <---
6 42951355
7 42951355
8 42951355
9 42951355
10 42951355
11 42951706 <---
11 rows selected.
SQL>
As you can see there is no way to tell what row was last updated/inserted.
SY.
[Updated on: Sat, 28 May 2016 07:00] Report message to a moderator
|
|
|