472,334 Members | 1,508 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,334 software developers and data experts.

latest row inserted

Hi friends,

how to see all the inserted rows of a particular date of a table.

regards
rohit
Mar 25 '08 #1
10 8155
ok.......need help

thanks
bye
Mar 25 '08 #2
amitpatel66
2,367 Expert 2GB
ok.......need help

thanks
bye
For latest row, you can use MAX(ROWID)
Mar 25 '08 #3
For latest row, you can use MAX(ROWID)

where ROWID > 20

doesn't meant that the selected rows are inserted by today
Mar 25 '08 #4
amitpatel66
2,367 Expert 2GB
where ROWID > 20

doesn't meant that the selected rows are inserted by today
If you use ROWID > 20 in your WHERE condition, the query will error out and will not work. I suggested you to make use of ROWID = MAX(ROWID) to get the last record inserted in to the table.
Mar 26 '08 #5
Saii
145 Expert 100+
Do you have any date column in your table that stores this information?
Mar 26 '08 #6
If you are running 10g or higher, you can use the ORA_ROWSCN pseudocolumn, which can be translated to a timestamp using the SCN_TO_TIMESTAMP function.

Note, however, that data that was imported from another instance have invalid SCN:s and will raise an exception. So, I wrote this little function that has proven quite handy; it just returns NULL whenever there's an imported row with an invalid SCN.

Expand|Select|Wrap|Line Numbers
  1. CREATE OR REPLACE function rowdate( rowscn in number )
  2. return date
  3. as
  4.   l_rowts  timestamp;
  5.   bad_scn  exception;
  6.   pragma exception_init( bad_scn, -8181 );
  7. begin
  8.        l_rowts := scn_to_timestamp( rowscn );
  9.        return cast( l_rowts as date);
  10.        exception when bad_scn then
  11.                      return null;
  12. end;
  13. /
  14.  
  15.  
So, a "select * from mytab where rowdate( ora_rowscn ) > trunc( sysdate )" will return today's rows.

Note that this will give you not only rows inserted today, but also the updated ones.
Mar 26 '08 #7
Do you have any date column in your table that stores this information?
find pelle's reply and try to do more with SCN....
that what the result is....
Mar 27 '08 #8
If you are running 10g or higher, you can use the ORA_ROWSCN pseudocolumn, which can be translated to a timestamp using the SCN_TO_TIMESTAMP function.

Note, however, that data that was imported from another instance have invalid SCN:s and will raise an exception. So, I wrote this little function that has proven quite handy; it just returns NULL whenever there's an imported row with an invalid SCN.

Expand|Select|Wrap|Line Numbers
  1. CREATE OR REPLACE function rowdate( rowscn in number )
  2. return date
  3. as
  4.   l_rowts  timestamp;
  5.   bad_scn  exception;
  6.   pragma exception_init( bad_scn, -8181 );
  7. begin
  8.        l_rowts := scn_to_timestamp( rowscn );
  9.        return cast( l_rowts as date);
  10.        exception when bad_scn then
  11.                      return null;
  12. end;
  13. /
  14.  
  15.  
So, a "select * from mytab where rowdate( ora_rowscn ) > trunc( sysdate )" will return today's rows.

Note that this will give you not only rows inserted today, but also the updated ones.

Thanks Pelle .....
Its a good reply....
Mar 27 '08 #9
If you are running 10g or higher, you can use the ORA_ROWSCN pseudocolumn, which can be translated to a timestamp using the SCN_TO_TIMESTAMP function.

Note, however, that data that was imported from another instance have invalid SCN:s and will raise an exception. So, I wrote this little function that has proven quite handy; it just returns NULL whenever there's an imported row with an invalid SCN.

Expand|Select|Wrap|Line Numbers
  1. CREATE OR REPLACE function rowdate( rowscn in number )
  2. return date
  3. as
  4.   l_rowts  timestamp;
  5.   bad_scn  exception;
  6.   pragma exception_init( bad_scn, -8181 );
  7. begin
  8.        l_rowts := scn_to_timestamp( rowscn );
  9.        return cast( l_rowts as date);
  10.        exception when bad_scn then
  11.                      return null;
  12. end;
  13. /
  14.  
  15.  
So, a "select * from mytab where rowdate( ora_rowscn ) > trunc( sysdate )" will return today's rows.

Note that this will give you not only rows inserted today, but also the updated ones.
yes pelle, that will work. can you check with this one:

select * from mytab where scn_to_timestamp( ora_rowscn ) - 0 > sysdate - 1

The function "scn_to_timestamp" returns "systimestamp" type data.
And if you do:
select systimestamp - 1 from dual
it returns sysdate type data.
Mar 27 '08 #10
Thanks for the tip.

ORA_ROWSCN of very old row might be too old to be a valid SCN.
In that case, using scn_to_timestamp will give error:

ORA-08181: specified number is not a valid system change number
ORA-06512: at "SYS.SCN_TO_TIMESTAMP", line 1

But, in case of a very recent row, this will work.

@rohitbasu77
Jan 27 '12 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: hshen | last post by:
Hi All, I have encountered a weird behavoir of embedded MySQL. Through a simple program I made (in Delphi 6), I can insert rows to a table...
2
by: george | last post by:
This is like the bug from hell. It is kind of hard to explain, so please bear with me. Background Info: SQL Server 7.0, on an NT box, Active...
11
by: serge | last post by:
When i debug a trigger is it possible to add a WATCH on the INSERTED or DELETED? I think not, at least I couldn't figure out a way to do so....
4
by: Mark | last post by:
Hey folks, I'm looking at making the following query more efficient potentially using the ranking functions and I'd like some advice from the...
0
by: sajithamol | last post by:
Is there in any way to retrieve the values that are present in the recently inserted row in DB2?
3
by: JurgenvonOerthel | last post by:
I want to replace one element in a list<stringby a list<stringand I need to obtain an iterator to the first element in the inserted list. In code:...
0
by: Gabriel Genellina | last post by:
En Mon, 05 May 2008 08:26:45 -0300, Vaibhav.bhawsar <bhawsar.vaibhav@gmail.comescribió: Use a Queue object to communicate between threads. The...
8
by: Tony Toews [MVP] | last post by:
Thanks to a posting by fellow MVP Steve Foster On a computer that is running Windows Vista, Windows Server 2008, or Windows XP, an incorrect...
3
by: ghssal | last post by:
how i can select the latest order for a customer in oracle forms and save this order as a new order whith new date. i use GROUP BY customer_ID and...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.