Rownum and last inserted row !!!!!!!!!!!!

hi everybody,
I am at present using oracle 8i Release 2. According to my knowledge and "Oracle 8 complete reference", when we use ROWNUM, the rownum is decided when the data is selected from the database. So when we use "order by" clause actually the rownum gets jumbled up.
But to my surprise when i did something like this on my SQl prompt row num is acting very "innocent" :)
<Code>
1* select rownum, empno from emp
SQL> /
ROWNUM EMPNO
1 7369
2 7499
3 7521
4 7566
5 7654
6 7698
7 7782
8 7788
9 7839
10 7844
11 7876
12 7900
13 7902
14 7934
15 1
15 rows selected.
SQL> select rownum, empno from emp order by empno;
ROWNUM EMPNO
1 1
2 7369
3 7499
4 7521
5 7566
6 7654
7 7698
8 7782
9 7788
10 7839
11 7844
12 7876
13 7900
14 7902
15 7934
15 rows selected.
</Code>
As you can see rownum is ordered again .. m i missing something.
B)
Is it possible to get a row that was inserted last. Does oracle guarantee that data retrieval will be according to the time of inssertion !!
Thanx in advance
Chetan

Rownum is decided afeter the complete execution of ur SQL statment (it includes ordey by, group by, where etc.).
you can get the last inserted row using:
select * from emp where rowid=
(select max(rowid) from emp);
Regards
Riaz

Similar Messages

  • Last Inserted Row in a Table

    Hi,
    I want to select only the last inserted row in a table. Can anybody help me how can i get it.
    Eg
    select * from emp;
    empno ename sal
    12 abc 100
    13 xyz 200
    Now i have inserted a row as
    Insert into emp values (14,'Rohit',500);
    So i only want to select the last inserted row i.e.. empno 14 (in this case).
    Thanks
    Bye
    Rohit Taneja

    Thanks to all for replying.
    But the result is not which i desire.
    I have deleted the existing row in the same table as
    SQL> Delete from emp where empno = 13;
    1 row deleted.
    Then i inserted a new row as
    SQL> insert into emp values(10,'SRI',200);
    1 row created.
    Then i committed the work
    SQL> commit;
    Commit complete.
    But still am getting the last row as
    SQL> select * from emp
    where rowid=(select max(rowid)
    from emp);
    EMPNO ENAME SAL
    14 ROHIT 500
    as the solution.
    But here i am supposed to get the row with empno 10.
    I have tried both the queries and still geting the same result.
    Please look aat it again,
    Thanks in advance
    Bye
    Rohit Taneja
    Hi,
    I want to select only the last inserted row in a
    table. Can anybody help me how can i get it.
    Eg
    select * from emp;
    empno ename sal
    12 abc 100
    13 xyz 200
    Now i have inserted a row as
    Insert into emp values (14,'Rohit',500);
    So i only want to select the last inserted row i.e..
    empno 14 (in this case).
    Thanks
    Bye
    Rohit Taneja

  • How to fetch last inserted row in MySQL

    Hi,
    I am trying to get the last inserted row in MySql..but not able to fetch it.
    this is what i used
    i have one column order_id which is auto_increment
    SELECT * FROM tablename WHERE order_id=(SELECT MAX(order_id) FROM tablename)
    any help is appreciated .
    the usage of lastinsert() method is also not successful
    chintan

    Hello
    Given you have a date column, you can use it to determine the latest row. However, there is still a chance that two rows were inserted at exactly the same time in which case you will need something in addition to your date column to decide which is the latest...
    The first option uses a sub query and the second uses analytics, as does the 3rd - however with the 3rd, if 2 rows have exactly the same date and time, it will pick one at random unless you include another column in the order by to determine the latest...
    select
    FROM
        your_table
    WHERE
        your_date_column = (SELECT MAX(your_date_column) from your_table)
    SELECT
    FROM
            select
                a.*,
                MAX(your_date_column) OVER() max_date_column
            FROM
                your_table a
    WHERE
        your_date_column = max_date_column
    SELECT
    FROM
            select
                a.*,
                ROW_NUMBER OVER(ORDER BY your_date_column DESC) rn
            FROM
                your_table a
    WHERE
        rn = 1HTH
    David

  • Getting the last inserted row

    Hi
    I want to get the ID for the last inserted row in another view (not the ones I have in my page), to pass it to a web service. How can I get it?
    This returns the first ID in the table: ${bindings.myIterator.RequestId}
    This one doesn’t work either: ${bindings.myIterator.currentRow.RequestId}
    It shows the following exception
    1. JBO-29000: Unexpected exception caught: java.lang.RuntimeException, msg=javax.servlet.jsp.el.ELException: Unable to find a value for "RequestId" in object of class "model.Travel_ViewRowImpl" using operator "."
    2. javax.servlet.jsp.el.ELException: Unable to find a value for "RequestId" in object of class "model.Travel_ViewRowImpl" using operator "."
    What does ${bindings.myIterator.currentRow.dataProvider} returns?

    Hi,
    while this is close to the correct syntax it is not complete
    ${bindings.myIterator.currentRow.RequestId}
    this would attempt to call set/get RequestId on the Row class, which doesn't have this property. It has a property getAttribute() but this doesn't allow you to pass an argumentbecause of EL limitations.
    Work around: Create an attribute binding for the "RequestId" attribute and call it with
    #{bindings.RequestId.inputValue}
    ADF always ensures that the currentRow's RequestId is the one obtained from the Attribute binding
    Frank

  • First And Last Visible Row - JTable

    I have a JTable on a ScrollPane backed by a TableModel, which provides a view on a potentialy large database table. It would be very helpfull if I could find the First and the Last visible row in the JTable every time it makes an elementAt request via TableModel interface, so that the cache underneeth the TableModel could make more intelegent descissions as to when to request more rows from the DB. I cant seem to see any methods on JTable or JScrollpane( and subclasses ) to acheive this. I would greatly appreciate any sugestions.

    use
    Rectangle rect = MyTable.getVisibleRect();
    Point point = rect.getLocation();
    int firstRow = myTable.rowAtPoint( point ) );
    point.setLocation( rect.getX() + rect.getWidth(),
                             rect.getY() + rect.getHeight() );
    int lastRow = myTable.rowAtPoint( point ) );

  • How to retrieve the last inserted row

    This may be a question with a very known answer but I couldn't find any within this forum.
    What is the proper way to retrieve the just inserted record ?
    I'm accessing the DB from external Java and at this moment I use a timestamp column in order to retrieve the inserted row. So I generate an unique timestamp ('20020615184524356') which I inserted during the insert operation. I retrieve the just inserted row using "select * from fooTable where(timestamp='20020615184524356')".
    Is this the general idea or am I totally wrong ?

    hi Shaik Khaleel,
    Just wanted to clarify my doubts regarding rowid.
    Please refer the subject as "abt rowid" in previous posting and ur reply for that was
    "its an unique number throughout the database, its an hexadecimal number. it assigns the rowid of the deleted row in future , but not to the immediate insertation row."
    As u have mentioned the rowid of the deleted row can be assigned to a new row in future,
    wont the following query fail.
    select * from temp where rowid=(select max(rowid) from temp); -- in oracle. ~chandru

  • ALV: Edit, change and delete/insert rows

    Hi all,
    starting from an ALV layout (5 rows) empty and ready for inserting data I can insert data but I select two rows, for example, and by pressing the "delete" icon, after the refresh
    CALL METHOD lo_grid->set_selected_rows
    EXPORTING
    it_row_no = loc_t_nrows
    is_keep_other_selections = ''.  "
    CALL METHOD lo_grid->refresh_table_display.
    I find my new layout without the selected rows but empty.
    How can I maintain the data in my layout (passing them to internal tables) to have my layout always up to date?
    Thanks for your kind support.
    Regards,
          Giovanni

    HI
    BCALV_EDIT_04  BCALV_EDIT_04 Check these programs.
    Cheers
    Ram

  • Exact height on 1st and last table row

    PLease--How do I modify this script so that it will affect the first and the last row.I out of ideas.--- app.activeDocument.stories.everyItem().tables.everyItem().rows.everyItem(0).properties = {autoGrow:false, minimumHeight:"14pt"};

    @Bob – To get access to the first row forget the everyItem(0) in your script. Instead write rows[0], for the last row write rows[-1].
    //First row of every table in the document:
    app.activeDocument.stories.everyItem().tables.everyItem().rows[0].properties = {autoGrow:false, minimumHeight:"14pt"};
    //Last row of every table in the document:
    app.activeDocument.stories.everyItem().tables.everyItem().rows[-1].properties = {autoGrow:false, minimumHeight:"14pt"};
    If you have tables with one single row the last row is the first row. The script will not break.
    To get the exact height, there are two options:
    minimumHeight
    height
    See Jongware's online documentation of  JavaScript:
    http://jongware.mit.edu/idcsjs5.5/pc_Rows.html
    Uwe

  • 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.

  • Append screen inserted row to internal table

    Hi Experts,
    I have created a program using table control. But after filling a row when i press enter the entire row getting blank.
    So i need to append the last inserted row from table control to internal table so that when i press enter that row remains on screen.
    Thanks & Regards
    Ashutosh Katara

    Hi,
    try this code  in PAI,
    IF sy-ucomm = 'ENTER'.
      if  tabc-col1 is NOT INITIAL and
         tabc-col2 is NOT INITIAL and
        tabc-col3 is NOT INITIAL and
         tabc-col4 is NOT INITIAL.
        w_tab-field1 =  tabc-col1.
        w_tab-field2 = tabc-col2.
        w_tab-field3 = tabc-col3.
        w_tab-field3 =  tabc-col4.
       modify <itab> FROM <workarea> INDEX sy-tabix.
    ENDIF.
    ENDIF

  • Last inserted record

    HI,
    we have created a table with a field ID.
    we have inserted 1000 records in that table,.
    I want to retrieve only the last inserted record.
    How it's possible?
    is it possible with rowid?
    e.g:
    CREATE TABLE TEST(id number(2));
    insert into TEST values(1);
    insert into TEST values(2);
    insert into TEST values(3);
    insert into TEST values(4);
    insert into TEST values(5);
    In this case i want to retrieve only 5.
    How we can achieve this?

    There is no concept of order in a heap table. Blocks can be reused so the ROWID cannot ever be used to determine when a row was inserted. The only way to determine the last row that was inserted into a table is to use a timestamp and/or a sequence column. If you need to determine the last inserted row and you don't already have a timestamp or sequence column, you need to add one.
    HTH
    David

  • How to delete duplicate rows in oracle and retaining last duplicate rows

    Hi,
    I'm having millions of records in the table .Some duplicate values/rows are inserted in it.
    I just want to delete duplicate rows but also want to retain the last duplicate row.
    For eg if one record is found three times ,i want to delete first and second record and retain
    the third one i.e the last inserted one.
    Regards
    Paramdeep Singh

    user13310594 wrote:
    Hi,
    I'm having millions of records in the table .Some duplicate values/rows are inserted in it.
    I just want to delete duplicate rows but also want to retain the last duplicate row.
    For eg if one record is found three times ,i want to delete first and second record and retain
    the third one i.e the last inserted one.Hi Paramdeep,
    To start with, since you do not wish to keep multiple rows with same values, why allow them to get inserted in the first place?
    Wouldn't it be easier to block duplicate rows from inserting by creating a Unique constraint on Column(s) that define a row as duplicate, then rather deleting duplicate rows periodically?
    For deleting duplicate rows, there are N number of techniques available. Always remember, you need to have a rigid criteria that marks row as duplicate.
    [url http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:15258974323143]this is one recomended by tom for large tables.
    Vivek L

  • I am trying to insert rows for alert_id 22 with diff abc_id and xyz_id

    I am trying to insert rows for alert_id 22 with diff abc_id and xyz_id
    these inserts will store in two tables that I have to join in the cursor.
    I have written cursor without passing cursor parameters. but here i need to pass acb_id and xyz_id along with alert_id.
    then if these are saticified with alert_id 22 then I want to stop the loop run, else i need to continue the loop. bcause the abc_id and xyz_id are diff for alert_id 22
    This is the issue I am facing!
    Please let me know if you have any idea. Let me know how to use cursor parameters here and in loop.
    Sample proc like this::
    Declare
    main_cursor
    another_cur
    alert_cur
    begin
    need to check first abc_id,xyz_id is already exist with alert_id 22
    if this set of records already exists then
    exit from the loop
    else
    continue with
    loop
    here coming the insert statements with different condition getting from first two cursors.(this part is ok for me)
    end loop
    end if
    Please write the logic if any idea on this.
    -LRK

    I want to stop if already alert_id is exist!

  • Insert row and delete row in a table control

    Hi Experts,
    I am using a table control in module pool programming, How can I Insert row and delete row in a table control?
    Thanks in Advance....

    Santhosh,
    Iam using this code..
    FORM fcode_delete_row
                  USING    p_tc_name           TYPE dynfnam
                           p_table_name
                           p_mark_name   .
    -BEGIN OF LOCAL DATA----
      DATA l_table_name       LIKE feld-name.
    data: p_mark_name type c.
      FIELD-SYMBOLS <tc>         TYPE cxtab_control.
      FIELD-SYMBOLS <table>      TYPE STANDARD TABLE.
      FIELD-SYMBOLS <wa>.
      FIELD-SYMBOLS <mark_field>.
    -END OF LOCAL DATA----
      ASSIGN (p_tc_name) TO <tc>.
    get the table, which belongs to the tc                               *
      CONCATENATE p_table_name '[]' INTO l_table_name. "table body
      ASSIGN (l_table_name) TO <table>.                "not headerline
    delete marked lines                                                  *
      DESCRIBE TABLE <table> LINES <tc>-lines.
      LOOP AT <table> ASSIGNING <wa>.
      access to the component 'FLAG' of the table header                 *
        ASSIGN COMPONENT p_mark_name OF STRUCTURE <wa> TO <mark_field>.
    if <MARK_FIELD> = 'X'.
        PERFORM f_save_confirmation_9101.
        IF gv_answer EQ '1'.
          DELETE <table> INDEX syst-tabix.
          IF sy-subrc = 0.
            <tc>-lines = <tc>-lines - 1.
          ENDIF.
          ELSE.
          ENDIF.
        ENDIF.
      ENDLOOP.
    in this code   ASSIGN COMPONENT p_mark_name OF STRUCTURE <wa> TO <mark_field>.
    if <MARK_FIELD> = 'X'.
    this code is not working...

  • Runtime error when inserting rows in hrp1018 and hrt1018 tables

    Hi All,
    I have a requirement to insert row in hrp1018 and hrt1018 tables.These tables are interlinked.So, I have used FM 'RH_INSERT_INFTY'. The exact code which I have used is as follows.
    *****************************************code***************************************************************
    << Please post only the relevant portion of the code >>
    The runtime error which is coming is as follows:
    Error analysis
        An internal error in the database interface occurred during access to
        the data of table "HRT1018 ".
        The situation points to an internal error in the SAP software
        or to an incorrect status of the respective work process.
        For further analysis the SAP system log should be examined
        (transaction SM21).
        For a precise analysis of the error, you should supply
        documents with as many details as possible.
    Please let me know why this error is coming.I am not able to find out mistake in the FM and form used in the code.
    Thanks in advance,
    BBKrishna.
    Edited by: Rob Burbank on Jun 9, 2009 1:31 PM

    I am adding the code once again.Please let me know why the error is coming up.
    lv_mproj = 'BLDNG'.
      wa_p1018-mandt = sy-mandt.
      wa_p1018-otype = '9M'.
      wa_p1018-objid = '50009650'.
      wa_p1018-begda = '20090608'.
      wa_p1018-endda = '99991231'.
      wa_p1018-infty = '1018'.
      wa_p1018-plvar = '01'.
      wa_p1018-otype = '9M'.
      wa_p1018-istat = '1'.
      append wa_p1018 to it_p1018.
      repid = sy-repid.
    *Updating hrp1018 and hrt1018 tables
      CALL FUNCTION 'RH_INSERT_INFTY'
        EXPORTING
        FCODE                     = 'INSE'
        VTASK                     = 'D'
         AUTHY                    = ' '
          REPID                   =  repid
          FORM                    = 'FILL_TABS'
        TABLES
          INNNN                   = it_p1018
    EXCEPTIONS
       NO_AUTHORIZATION          = 1
       ERROR_DURING_INSERT       = 2
       REPID_FORM_INITIAL        = 3
       CORR_EXIT                 = 4
       BEGDA_GREATER_ENDDA       = 5
       OTHERS                    = 6
      IF SY-SUBRC <> 0.
        CALL FUNCTION 'BALW_BAPIRETURN_GET'
          EXPORTING
            TYPE                             = SY-MSGTY
            CL                               = sy-msgid
            NUMBER                           = SY-MSGNO
      PAR1                             = ' '
      PAR2                             = ' '
      PAR3                             = ' '
      PAR4                             = ' '
      LOG_NO                           = ' '
      LOG_MSG_NO                       = ' '
         IMPORTING
           BAPIRETURN                        = return_rec
    EXCEPTIONS
      ONLY_2_CHAR_FOR_MESSAGE_ID       = 1
      OTHERS                           = 2
        IF SY-SUBRC <> 0.
            lv_mproj = text-011
                      ELSE.
                      ii_return = return_rec.
                      CONCATENATE                  ii_return-type '-' ii_return-message
                      INTO lv_err_msg SEPARATED BY SPACE.
        ENDIF.
      ENDIF.
    *RHCD_TAB-PROZT
       FORM fill_tabs TABLES ins_tab
                   USING ins_set ins_index.
      DATA : BEGIN OF set.
              INCLUDE STRUCTURE wplog.
      DATA : END   OF set.
      DATA: BEGIN OF h_pt1018.             "to initialize INS_TAB
              INCLUDE STRUCTURE pt1018.
      DATA: END OF h_pt1018.
      REFRESH ins_tab.
      set = ins_set.
      CASE set-infty.
        WHEN '1018'.
          h_pt1018-posnr = lv_mproj.
          h_pt1018-prozt = '100.00'.
          IF NOT ( h_pt1018 IS INITIAL ).
            CLEAR ins_tab.
            ins_tab+36(8) = lv_mproj. "h_pt1018.
            ins_tab+134(5) = '100.00'.
            APPEND ins_tab.
          ENDIF.
      ENDCASE.
    ENDFORM.

Maybe you are looking for

  • Folder names with diacritics & NFS shares

    OK; sometimes things appear simple but are not. Sharing files with an OSX client has been, and is a nightmare in a Linux environment. We have a mostly Ubuntu environment and have tried Samba, and NFS. After a significant amount of work the Mac can do

  • Use of Table EDPAR(EDI Partner Table)

    Hi All, Here , what is the significance of providing external partner.. I was under the impression that this will be used for Xref. For Eg, in our current Non-SAP to Non-SAP System , we use EDI for data transfer. Customer will send its Warehouse numb

  • Has Anyone Ordered the MBP with Glossy Display ???

    I am on the fence like many people (except professional photographers) about this issue. I have seen it on the MacBook in the Apple Store and I cannot decide. The desktop blue color looks like true blue while the matte MBP look soooo washed out in co

  • X not starting on new installation

    Hello all! today I decided to try arch for the first time. THe installation went well, but now i cannot get x to start. I have read through most of the xorg wiki and cannot find a way to solve my problem. Here is the crash log: http://bpaste.net/show

  • TREX 7.0 System AIX 5.3 DB2 Error FCO-00011  The step extractTrexBinaries

    Hi Colleagues, In the process 6 of 12 the installation the trex stopped with this error, FCO-00011  The step extractTrexBinaries with step key |TREX_NW_CI_MAIN|ind|ind|TREX|ind|0|0|TREX_MAIN|ind|ind|TREX|ind|0|0|TREX_BINARY_INST|ind|ind|TREX|ind|4|0