How to determine the last record inserted

hi
I have a table abc ( x number, y number, z date ) columns, there
is no primary or unique key.
I have been inserting values into it. there r some duplicate
values to.
but now I want to modify only the record inserted at the end.
i.e
if initially ABC is having
x y z
10 20 01-nov-2001
11 20 01-nov-2001
out of these records I want to change the value of x to 50 for
the record which was inserted last or shall I say whose z is the
greatest.
I have been trying to do but what I see that the z column is not
getting the time in increasing order. i.e even though I tried to
display the dated in dd-mon-yyyy 24hh:mm:ss format still and I
found that date is not consistant. the record I inserted first
is have a much more value than the record I inserted last.
please help...
Sreekant

rowid refers to the current position of the record; if the
record has been moved (and there are any number of reasons why
the database might shift a record) the order of rowid will not
reflect the order of insertion.
the only way to guarantee order of insertion is to timestamp the
record. if I understand the original posting, you have been
doing this.
Now you should have been using SYSDATE. if you are saying that
SYSDATE is giving you inconsistent results then you have a real
problem: has somebody been tinkering with your database server -
changing the system clock or something?
Or are you using some other method to set the value for Z
column? If so, what?
rgds, APC

Similar Messages

  • How to restrict the last record and not moving to next reocrd

    1) how to restrict the last record and not moving to next reocrd.
    2) Also for the F6 key(for new record).

    When you are on the last record, next-record will create a new one, so that my question is do you want to forbid new record creation.
    Francois

  • How to get the last record??

    Hi, I now have to get only the last record from one table
    from MS Access.
    I was looking for the useful method from API, however,
    I cannot get it.
    How to get only the last record from one table ???
    Please help, thanks.

    In RDBMS, row order is really not relavent by iteself. Meaning there is no such thing as 'last record' unless it's in the context of a column (e.g. timeStamp).
    Of course, rows are inserted and stored in some natural order, but you cannot assume they'll come back the same way in a 'Select *' as they were entered.
    So, if you mean last row as in last inserted row, I would add a timestamp field that's set at insert, or use a autonumber column. Either way, have a column that will always contain the highest number or newest timestamp, and then you can build your where clause from that.
    For instance, in Access, I have an autonumbered field called 'fred', with other columns. If I want the last record, I simply use the following:
    select * from atable where fred in (SELECT max(fred) AS Max FROM atable);
    the 'where in' clause will filter to only those records in the subsequent select statment, which of course is only one, the max of the column fred.
    bRi

  • How to determine the last transaction of a Batch Number

    Hello,
    For example,
    ITEMCODE - BATCHNUM - WHSCODE - LINENUM - DIRECTION
    ITEM1 - BATCH1 - WH1 - 0 - 0
    ITEM1 - BATCH1 - WH2 - 0 - 0
    ITEM1 - BATCH1 - WH1 - 1 - 1
    ITEM1 - BATCH1 - WH2 - 1 - 1
    How will I know that record number 4 is the last transaction regardless of the transaction type and warehouse code.  Is there any table which can help me solve this issue other than OIBT?
    Regards,
    Gilbert Ngo

    You could use the OINM Transnum (connected to the IBT1) to determine the last transaction:
    SELECT T1.[TransNum],
    T0.[ItemCode], T0.[BatchNum], T0.[WhsCode]
    FROM [dbo].[IBT1]  T0
    Join OINM T1 On T1.[BASE_REF] = T0.[BaseEntry]  and  T0.[BaseType] = T1.[TransType]

  • How to find the last records of the table in adventure work db

    hi all,
    i want to find out " how to receive a last records of the table (eg:  person.emailaddress ) in sql 2008 and 2005"
    Thanks

    If you are looking for the latest record( the one which got inserted/modified last) then use this query
    select top 1 * from person.emailaddress
    Order by ModifiedDate desc
    Satheesh
    My Blog |
    How to ask questions in technical forum

  • How to determine the "Last Value" in exception aggregation

    Hi gurus,
    I have a KeyFigure with an exception aggregation -Last value- by time.
    I report on a multiprovider ("containing" a infocube and a realtime infocube with BPS-InputLayout). I can correct separate Items with this BPS-Layout. So, at the end I have 2 values for one item.
    So, by these facts, my report shows the the last value for the specific KeyFigure, but I expected that both values (the value in the infocube and the correction via BPS)are sumed up.
    As this is due to the exception aggregation not the case, I could "overwrite" the normal value in the infocube with the BPS.
    But SAP determines the normal value in the Infocube as "Last Value", not the one in the correction cube, which is entered via BPS.
    How does SAP determine the "last value" as I can´t see any date...
    Thanks in advance!

    Thank you for your answer...
    I got the soltion by myself.
    I thought, Last Value means the last Value, depending on the time, but in my opinion the function last value should be called "Greatest Value".
    All figures with the same value for the reference characteristc are aggregated anyway.

  • How to get the last record from the database

    I am using MS Access database and Swings as GUI. I want to get the last record of a particular column from the table and store it as a varaible.

    Hi
    To get Last record of resultset, you have pass some parameter in constructor of CreateStatement.In such case Resultset should be scrollable and Readonly
    Example
    objStatement=objCon.createStatement ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
    mwwResultSet=cwwStatement.executeQuery(mwwSqlQuery);
    while(mwwResultSet.next())
    if(mwwResultSet.isLast())
    //Fetch the required column record.
    String abc=mwwResultSet.getString(1);
    I think this will work. Try it.
    bye

  • How to get the last record of an internall table ....

    Hi All..
    i want to get the last record of an internal table itab, and i want the the value of the last record.

    Hi,
         Use describe statment.
    data: lv_line type i.
        Describe table itab lines lv_line.
        read table itab into wa_itab index lv_line.
    regards,
    Santosh Thorat

  • How to determine the cursor record count before the "open cursor"?

    Is it possible to determine the record count of an explicit cursor without running a count()? Say, my cursor definition is something like this,
    CURSOR cur_vehicle
    IS
    SELECT os.order_id, os.order_item, vs.part_id
    vs.part_num,
    vs.iso_num,
    vs.model_yr
    vs.dealer_cde,
    vs.cust_cde,
    px.plant_cd
    FROM parts_source vs,
    orders_source os,
    plant_tbl_crossref px
    wHERE os.order_id = vs.order_id
    AND vs.part_id = os.part_id
    AND vs.plant_cde = px.plant_cde
    ORDER BY os.order_id;
    I want to log the count of records returned by the above cursor prior to the first fetch, without running a count(1) for the query in cursor select.
    I know adding " Count(1) over(order by null) " in the cursor SELECT will bring it. But that does not help me log the record count to some log file or table before opening the cursor for processing.
    To conclude, my objective is to update the record count of cursor in some table before processing

    sarvan wrote:
    Is it possible to determine the record count of an explicit cursor without running a count()?
    ..snipped..No. The only way to do it correctly is inside that select.
    Each select is a consistent read. Which means that if this is done as 2 select statements, the 1st select can see a different version of the data than the 2nd select statement. does. So if you want a count and that to be consistent and on the same version of the data than the select, it has to be done as part of the select.
    Also consider what a cursor is. It is not a result set of sorts that is created in memory upfront - with a convenient interface that tells you the size/number of rows of that result set.
    A cursor is basically a program that reads database data as input and produce output. A fetch from a cursor is an instruction for this program to execute and output data.
    There's no data set that is created by the cursor from which the count can be determined. The cursor program does have state variables - like +%RowCount+ that specifies how many rows the cursor has thus far output. And you need to run that cursor to the end (no more output) in order to determine the total number of rows output by the cursor.

  • How to determine the last time  a database was used

    Is it possible in to determine the time a CRUD operation occurred on a database?

    How can I activate the auditing? http://download-east.oracle.com/docs/cd/B19306_01/network.102/b14266/auditing.htm#i1011984
    Daljit Singh

  • How to Prevent the Duplicate record insertion by JDBC Receiver?

    HI Experts,
    I have File Sender to JDBC Receiver scenario.I am using SAP PI 7.1 system.
    Purpose of this Scenario is to read the data from specified file and INSERT or  UPDATE the same records in Oracle Database.
    Before inserting the data I want to check in the same table for prventing runtime error(Key fields Duplicatin).
    So if records with the same key fields are available in table then I want to UPDATE the same record instead of INSERT.
    Please Suggest me the poosbile way.
    Thanks & Regards
    Jagesh

    Hi Jagdesh,
    The JDBC receiver format has the following structure
    <root>
    <StatementName1>
    <dbTableName action=u201DUPDATEu201D | u201CUPDATE_INSERTu201D>
    <table>Table1</table>
    <access>
    <col1>val1</col1>
    <col2>val2new</col2>
    </access>
    <key>
    <col2>val2old</col2>
    <col4>val4</col4>
    </key>
    This structure creates a query in this way :
    UPDATE( OR UPDATE_INSERT) into Table1 set col1=val1 and col2 = val2new WHERE col2=val2old and col4=val4.
    The key field works like a Where clause. So for the receiver format when you specify the key, it checks the DB with that field as the where criteria. Hence for a UPDATE_INSERT query, when you specify the key field, it checks whether that value specified within the key field exists in the DB or not. Then it proceeds to execute the statement for only those values.
    Hence it makes sense to provide a primary key attribute in the key field of the JDBC receiver format.
    Regards,
    Kshitij

  • How to determine the last backup time?

    On my iPhone 4 I sync it to iTunes on my IMAC.
    I hit backup and it says "Backing up my iPhone"
    I then want to see the date and time of the last backup? How do I do that?
    I right click on the iPhone in Itunes and select "Restore from Backup" and the
    list shows a date/time of yesterday and then a selection that just shows the iPhone name. I can't see the backup (date/time) I just did.
    As I understand it from reading the sync and backup are actually different so
    I want to know the backup was successful and what timestamp is associated with that backup.

    iTunes > Preferences under the Devices tab.

  • How to determine the last form open in Forms 9i webforms??

    I am trying to find out if there is a built-in that tells you that you are on the last form in your application?? I've tried the :system.last_form and :system.current_form built-in's but to no avail... If anyone has done this, please let me know.
    Thank you kindly,
    Terry Sicard
    [email protected]

    Hi,
    Please see (Note: 176852.1 - Integrating Custom Applications with Oracle Applications Release 11i), Step 10-f.
    For the (Help > About) issue, please see if (Note: 556755.1 - Forms Version Not Showing On 'About Oracle Applications' Form From Help Menu) helps.
    Btw, I guess we had a similar discussion before in this EBS 11i Customized Oracle Forms and Reports.
    Regards,
    Hussein

  • HELP! How te retrieve the last row in MYSQL database using Servlet!

    Hi ,
    I am new servlets. I am trying to retireve the last row id inserted using the servlet.
    Could someone show me a working sample code on how to retrieve the last record inserted?
    Thanks
    MY CODE
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import java.io.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    public class demo_gr extends HttpServlet {
    //***** Servlet access to data base
    public void doPost (HttpServletRequest req, HttpServletResponse resp)
         throws ServletException, IOException
         String url = "jdbc:mysql://sql2.njit.edu/ki3_proj";
              String param1 = req.getParameter("param1");
              PrintWriter out = resp.getWriter();
              resp.setContentType("text/html");
              String semail, sfname, slname, rfname, rlname, remail, message;
              int cardType;
              sfname = req.getParameter("sfname");
              slname = req.getParameter("slname");
              rfname = req.getParameter("rfname");
              rlname = req.getParameter("rlname");
              semail = req.getParameter("semail");
              remail = req.getParameter("remail");
              message = req.getParameter("message");
              //cardType = req.getParameter("cardType");
              cardType = Integer.parseInt(req.getParameter("cardType"));
              out.println(" param1 " + param1 + "\n");
         String query = "SELECT * FROM greeting_db "
    + "WHERE id =" + param1 + "";
              String query2 ="INSERT INTO greeting_db (sfname, slname ,semail , rfname , rlname , remail , message , cardType ,sentdate ,vieweddate) values('";
              query2 = query2 + sfname +"','"+ slname + "','"+ semail + "','"+ rfname + "','"+ rlname + "','"+ remail + "','"+ message + "','"+ cardType + "',NOW(),NOW())";
              //out.println(" query2 " + query2 + "\n");
              if (semail.equals("") || sfname.equals("") ||
              slname.equals("") || rfname.equals("") ||
              rlname.equals("") || remail.equals("") ||
              message.equals(""))
                        out.println("<h3> Please Click the back button and fill in <b>all</b> fields</h3>");
                        out.close();
                        return;
              String title = "Your Card Has Been Sent";
              out.println("<BODY>\n" +
    "<H1 ALIGN=CENTER>" + title + "</H1>\n" );
                   out.println("\n" +
    "\n" +
    " From  " + sfname + ", " + slname + "\n <br> To  "
                                            + rfname + ", " + rlname + "\n <br>Receiver Email  " + remail + "\n<br> Your Message "
                                            + message + "\n<br> <br> :");
                   if (cardType ==1)
                        out.println("<IMG SRC=/WEB-INF/images/bentley.jpg>");
                   else if(cardType ==2) {
                        out.println("<IMG SRC=/WEB-INF/images/Bugatti.jpg>");
                   else if(cardType ==3) {
                        out.println(" <IMG SRC=/WEB-INF/images/castle.jpg>");
    else if(cardType ==4) {
                        out.println(" <IMG SRC=/WEB-INF/images/motocross.jpg>");
    else if(cardType ==5) {
                        out.println(" <IMG SRC=/WEB-INF/images/Mustang.jpg>");
    else if(cardType ==6) {
                        out.println("<IMG SRC=/WEB-INF/images/Mustang.jpg>");
    out.println("</BODY></HTML>");
         try {
              Class.forName ("com.mysql.jdbc.Driver");
              Connection con = DriverManager.getConnection
              ( url, "*****", "******" );
    Statement stmt = con.createStatement ();
                   stmt.execute (query2);
                   //String query3 = "SELECT LAST_INSERT_ID()";
                   //ResultSet rs = stmt.executeQuery (query3);
                   //int questionID = rs.getInt(1);
                   System.out.println("Total rows:"+questionID);
    stmt.close();
    con.close();
    } // end try
    catch (SQLException ex) {
              //PrintWriter out = resp.getWriter();
         resp.setContentType("text/html");
              while (ex != null) { 
         out.println ("SQL Exception: " + ex.getMessage ());
         ex = ex.getNextException ();
    } // end while
    } // end catch SQLException
    catch (java.lang.Exception ex) {
         //PrintWriter out = resp.getWriter();
              resp.setContentType("text/html");     
              out.println ("Exception: " + ex.getMessage ());
    } // end doGet
    private void printResultSet ( HttpServletResponse resp, ResultSet rs )
    throws SQLException {
    try {
              PrintWriter out = resp.getWriter();
         out.println("<html>");
         out.println("<head><title>jbs jdbc/mysql servlet</title></head>");
         out.println("<body>");
         out.println("<center><font color=AA0000>");
         out.println("<table border='1'>");
         int numCols = rs.getMetaData().getColumnCount ();
    while ( rs.next() ) {
              out.println("<tr>");
         for (int i=1; i<=numCols; i++) {
    out.print("<td>" + rs.getString(i) + "</td>" );
    } // end for
    out.println("</tr>");
    } // end while
         out.println("</table>");
         out.println("</font></center>");
         out.println("</body>");
         out.println("</html>");
         out.close();
         } // end try
    catch ( IOException except) {
    } // end catch
    } // end returnHTML
    } // end jbsJDBCServlet

    I dont know what table names and fields you have but
    say you have a table called XYZ which has a primary
    key field called keyID.
    So in order to get the last row inserted, you could
    do something like
    Select *
    from XYZ
    where keyID = (Select MAX(keyID) from XYZ);
    Good Luckwhat gubloo said is correct ...But this is all in MS SQL Server I don't know the syntax and key words in MYSQL
    This works fine if the emp_id is incremental and of type integer
    Query:
    select      *
    from      employee e,  (select max(emp_id) as emp_id from employee) z
    where      e.emp_id = z.emp_id
    or
    select top 1 * from employee order by emp_id descUday

  • How to get the last inserted record from a table ?

    :-) Hiee E'body
    I work on Oracle 8i and need to get the last
    record inserted in a table.
    I have tried using rownum and rowid pseudo-columns
    but that doesn't work.
    Can you please help me out ?
    :-) Have a nice time
    Vivek Kapoor.
    IT, Atul Ltd.,
    India.

    I'm not sure about 8i features.
    I assume here that you don't have 'Date-Time' stamp columns on the table which is the easiest way to determine the last inserted row in the table.
    If not try the following :-
    select address, piece, SQL_TEXT
    from V$SQLTEXT
    where upper(sql_text) like '%INSERT INTO TABLE_NAME%'
    Substiute the TABLE_NAME with the name of the actual table.
    Have fun.
    Regards,
    Shailender
    :-) Hiee E'body
    I work on Oracle 8i and need to get the last
    record inserted in a table.
    I have tried using rownum and rowid pseudo-columns
    but that doesn't work.
    Can you please help me out ?
    :-) Have a nice time
    Vivek Kapoor.
    IT, Atul Ltd.,
    India.

Maybe you are looking for

  • Adding link to the photo and Name in the outlook contact card -Enterprise wide

    How can I make the name and photo in the outlook contact card link to my profile page? I read articles where it is mentoined that the URL is set in Registry, currently my organization does not have any link associated with photo and name in contact c

  • Consumed Budget Getting Reversed

    Dear All, I am facing one typical error, please help me out to resolve the same. Issue:     Consumed Budget is getting reversed after MIGO Scenario:    I've Created a Material PO for which system has done the AVC check and posted the budget document

  • After iOS update, screen too long??

    Not sure the best way to word this, but it's been only today that this has been happening. The bottom and edges of my screen are cut off, and it's only been since this latest iOS update. It's like they're expecting my screen to be longer? Sometimes i

  • VB6 INSERT QUERY

    Hi, Can anyone give me the correct method for inserting a record into an access 2010 db? I have the connection details but not sure how to execute the actual query. Dim cmd As New ADODB.Command     'Dim cat As New ADOX.Catalog     'Dim dbpath As Stri

  • Register dll on client side through applet

    hi can any on e tell how to register a dll on client side from a signed applet. thanx