Can one retrieve only the Nth row from a table?

Hi,
Can anyone explain the execution order of the below query to fetch the nth row data.
SELECT * FROM t1 a
WHERE n = (SELECT COUNT(rowid)
FROM t1 b
WHERE a.rowid >= b.rowid);
Thanks,
Satya.

>
If you're interested in a more efficient way to get the Nth row of the table, in order by ROWID:
>
Perhaps you should change that to 'tremendously more efficient'?
Ran some tests of the two using a table that contained 50+ thousand records created from ALL_OBJECTS
CREATE TABLE EMP_ALL_OBJECTS AS SELECT * FROM ALL_OBJECTSThen ran your query (modified for the new table) for r_num = 10000. It returned immediately and used 925 consistent gets.
Ran the original query (modified for the new table) for '10000 = '. It took 3 minutes and used 24189252 consistent gets.
Thought maybe it was a fluke so ran the orginal query for '1 = '. It took the same 3 minutes and used 24189253 consistent gets.
Maybe someone else could try to reproduce these results?
Here is the plan for Frank's query
>
Execution Plan
Plan hash value: 3171438729
| Id | Operation | Name | Rows | Bytes |TempSpc| Cos
t (%CPU)| Time |
| 0 | SELECT STATEMENT | | 47057 | 7858K| | 19
93 (1)| 00:00:24 |
|* 1 | VIEW | | 47057 | 7858K| | 19
93 (1)| 00:00:24 |
|* 2 | WINDOW SORT PUSHED RANK| | 47057 | 7812K| 9664K| 19
93 (1)| 00:00:24 |
| 3 | TABLE ACCESS FULL | ALL_OBJECTS_EMP | 47057 | 7812K| | 2
39 (1)| 00:00:03 |
Predicate Information (identified by operation id):
1 - filter("R_NUM"=10000)
2 - filter(ROW_NUMBER() OVER ( ORDER BY ROWID)<=10000)
Note
- dynamic sampling used for this statement (level=2)
Statistics
0 recursive calls
0 db block gets
866 consistent gets
0 physical reads
0 redo size
1281 bytes sent via SQL*Net to client
407 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
1 rows processed
SQL>
>
And the plan for the original query
>
Execution Plan
Plan hash value: 308981268
| Id | Operation | Name | Rows | Bytes | Cost (
%CPU)| Time |
| 0 | SELECT STATEMENT | | 471 | 80070 | 10M
(1)| 35:14:03 |
|* 1 | FILTER | | | |
| |
| 2 | TABLE ACCESS FULL | ALL_OBJECTS_EMP | 47057 | 7812K| 239
(1)| 00:00:03 |
| 3 | SORT AGGREGATE | | 1 | 12 |
| |
|* 4 | TABLE ACCESS BY ROWID RANGE| ALL_OBJECTS_EMP | 2353 | 28236 | 238
(0)| 00:00:03 |
Predicate Information (identified by operation id):
1 - filter( (SELECT COUNT(ROWID) FROM "ALL_OBJECTS_EMP" "B" WHERE "B".ROWID<=
:B1)=1)
4 - access("B".ROWID<=:B1)
Note
- dynamic sampling used for this statement (level=2)
Statistics
7 recursive calls
0 db block gets
24189253 consistent gets
0 physical reads
0 redo size
1218 bytes sent via SQL*Net to client
408 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL>
>
Looks like the original query is doing a probe of the entire 2nd table for each row of the 1st table - almost a CARTESIAN result. It takes the same time no matter which record you are looking for.

Similar Messages

  • How to save the  selected rows from Advance table into database

    Hi
    I have requirement like..
    In custom page , Manager Search the Candidates and selects the candidate ROWS from advance table.
    The reqt is how to save the selected multiple rows into the database.

    hi Reetesh,
    In Custom page
    Supoose the Recruiter Search is for Position Finance Mangager , it retrieves 100 rows , out of which Recruiter select 10 rows .
    So in Such scenario how to save this 10 rows against Recruiter
    , i mean , Is i need to create custom table, to save Recruiter , these selected 10 rows.
    I hope u understand my question

  • ¿How can I to get the selected index from a table in sapui5?

    I have a multiselect table for each item I need to open a Dialog and bind then the table.
    How Can I to obtain the index position from my table?
    var myTable = sap.ui.getCore().byId(this.sId);
    var myItem = sap.ui.getCore().byId(myTable.getSelectedItem());
    Thanks in advance.

    Hi,
    You can also use getSelectedContexts of table instance to get the selected indices of sap.m.Table
    var aContexts = myTable.getSelectedContexts(true);
    for(var i = 0 ; i < aContexts.length ; i++)
    var selectedIndex = parseInt(aContexts[i].sPath .split("/")[2]);
    Thanks,
    Rumeshbabu S

  • How can I delete ONLY the GPS coordinates from my Hi Res images WITHOUT "Save four Web" or Lightroom

    Hello,
    I take hi res pics of rare wildlife and plants with both my Camera's and iPhone's GPS deliberately ENABLED. Use the photos and their GPS coordinates to document and plot my sightings with dates on maps. CANNOT disclose those locations to others. I do want to keep the metadata in my pics to the very end.
    Use Photohop Extended CS 6 MAC. Save files as hi res TIFF or PSD and sometimes e-mail/upload my pics to the web when I'm done.
    I CANNOT use "Save for Web" to delete my metadata — I don't want the jpeg's lossy compression. Need to preserve color profiles.
    Don't have Lightroom.
    How do use Photoshop to remove ONLY the GPS coordinates from my hi res images EXIF data??? Want to keep other EXIF data.
    Surely Adobe can provide this life-saving service?
    Thanks

    Yep, as others mentioned, just use Bridge and delete the entries there.  You can select a whole batch of files and do them all at once.

  • Refreshing only the single row of  ADF Table

    Hi All,
    I have a webcenter application where the ADF Applications has been deployed.Now the Data is coming onto the ADF Tables from a webservice.In that particular table i need to refresh only the single row(whichever selected by the user to edit ) or even a particular field with the updated values as well as need to validate and to create a message box saying about the errors if the validation goes wrong.
    Please suggest!!

    Hi,
    if "updated value" mean that the value got changed on the middle tier (not the browser client) then the update requires the table to be partially refreshed. If the user edits a row and in this row has dependent fields, then this can be achieved by partially refreshing the column. Note that ADF Faces tables don't refresh just one cell
    Frank

  • How to delete the committed row from a table from its VOImpl class ??

    I am new to ADF and I have problem to solve. To perform roll back I am using fetching key before roll back and setting it after undo operation, so that I can stay back in the currently selected row. But in my case I am using application model commit for one LOV attribute selection in the row. So when ever I am performing roll back operation after inserting a row, the values other than this committed LOV attribute gets roll backed, but I need remove the entire row from table. Does there any option to remove a row based on the attribute values of a row from VO's row implementation or from bean class in a performance optimized way ?
    Thanks in advance..........

    http://java.sun.com/javase/6/docs/api/javax/swing/table/DefaultTableModel.html#removeRow(int)
    Why did you mark it answered but gave no dukes to finalight? That's not how it works.
    You should mark his answer as correct and give him at least one duke, for the effort!

  • How to return the entire row from a table

    Hi guys,
    Tabl A
    FirstName varchar2(10),
    Age Number,
    Add varchar2(100),
    Table B
    Filedname varchar2(200), -- contains all the fields of table A
    Datatype varchar2(100), -- Contains the datatypes of the filedname
    Length Number -- contains the length of the fileds
    Now how can i return the entire row from table A with the datatype and its length.
    Any help would be appreciated ?
    Here is the query I wrote but it how to take the datatype and its length..
    create or replace procedure disp_table_data
    as
    type r_cursor is REF CURSOR;
    c_A r_cursor;
    er A%rowtype;
    begin
    open c_A for select * from A;
    loop
    fetch c_A into er;
    exit when c_A%notfound;
    dbms_output.put_line(er.FirstName||'--'||er.Age);
    end loop;
    close c_A;
    END;
    /

    Guys,
    I want column value from table A and its corresponding data_type and length from table B. I think I cant do it through joins.
    Any idea would be appreciated ?.
    Example ..
    Tabl A
    FirstName varchar2(10),
    Age Number,
    Add varchar2(100)
    insert into A values('John',24,'Boston');
    Table B
    Filedname varchar2(200), -- contains all the fields of table A
    Datatype varchar2(100), -- Contains the datatypes of the filedname
    Length Number -- contains the length of the fileds
    insert into B values('FirstName','varchar2',10); -- this is coming from table A.
    Output should be like this...
    John,Varchar2,10
    Here (John is the FirstName - coming from table A, Varchar2 is a Datatype and 10 is the Length which are coming from table B ). Only column values are coming from table A , corresponding datatype and length are coming from B.
    Any idea would be appreciated ?
    Thanks.

  • Make only the new row in a table editable and other rows display mode.

    Hiii all,
    I am working on the component GSWISET, there is a table view for substitutes, the requirement is to show all the rows in the table view in display mode. Whenever the user clicks the button (Add employee), a search popup triggers and the user selects an employee from that and it will come as a new row in the table view. Here I need to be able to make only the new row editable and all the other rows in display mode.
    Could you please suggest a way to achieve this. Thanks for your time..

    Hi,
    Try with  the code below in.htm page
    data: lv_displaymode  TYPE string.
      IF controller->view_group_context->is_view_in_display_mode( controller ) = abap_true.
        lv_displaymode = 'X'.
      ELSE.
        lv_displaymode = ' '.
      ENDIF.
    if lv_displaymode = 'X'.
    <chtmlb:tableExtension tableId = "Substitutes"
                           layout  = "FIXED" >
      <chtmlb:configTable actions               = "<%= controller->gt_button %>"
                          id                    = "Substitutes"
                          onRowSelection        = "select"
                          selectedRowIndex      = "<%= substitutes->SELECTED_INDEX %>"
                          selectedRowIndexTable = "<%= substitutes->SELECTION_TAB %>"
                          table                 = "//Substitutes/Table"
                          width                 = "100%"
                          selectionMode         = "<%= substitutes->selection_mode %>"                    
                          visibleFirstRow       = "<%= substitutes->VISIBLE_FIRST_ROW_INDEX %>"
                          usage                 = "ASSIGNMENTBLOCK"
                          headerText            = "<%= controller->gv_header_text %>" />
    </chtmlb:tableExtension>
    else.
    <chtmlb:tableExtension tableId = "Substitutes"
                           layout  = "FIXED" >
      <chtmlb:configTable actions               = "<%= controller->gt_button %>"
                          id                    = "Substitutes"
                          onRowSelection        = "select"
                          selectedRowIndex      = "<%= substitutes->SELECTED_INDEX %>"
                          selectedRowIndexTable = "<%= substitutes->SELECTION_TAB %>"
                          table                 = "//Substitutes/Table"
                          width                 = "100%"
                          selectionMode         = "<%= substitutes->selection_mode %>"
                          allRowsEditable       = "TRUE"
                          visibleFirstRow       = "<%= substitutes->VISIBLE_FIRST_ROW_INDEX %>"
                          usage                 = "EDITLIST"
                          headerText            = "<%= controller->gv_header_text %>" />
    </chtmlb:tableExtension>
    endif.
    Regards,
    Gangadhar.S
    Edited by: gangadhar rao on Dec 24, 2010 12:49 PM

  • How can I get only the dual rows?

    Dear gurus,
    I want to retrieve the rows that are dual in my SQL.
    select grb.num_matricula
    from gb_ficha_financ_assistido gff,
    gb_rubricas_previdencial grp,
    gb_recebedor_beneficio grb
    where gff.cd_rubrica = grp.cd_rubrica
    and (gff.cd_fundacao = grb.cd_fundacao
    and gff.seq_recebedor = grb.seq_recebedor)
    and grp.id_rub_suplementacao = 'S'
    and gff.dt_referencia = '01/12/2004'
    group by grb.num_matricula
    The query above return 1414 rows...
    But when I execute the query below I recived 1430 rows. The only modification is the column cod_entid that was add.
    select grb.num_matricula matricula ,grb.cod_entid
    from gb_ficha_financ_assistido gff, gb_rubricas_previdencial grp,
    gb_recebedor_beneficio grb
    where gff.cd_rubrica = grp.cd_rubrica
    and (gff.cd_fundacao = grb.cd_fundacao
    and gff.seq_recebedor = grb.seq_recebedor)
    and grp.id_rub_suplementacao = 'S'
    and gff.dt_referencia = '01/12/2004'
    group by grb.num_matricula, grb.cd_empresa
    The results let me think that exists in some cases diferents cod_entid with the same num_matricula and this is wrong.
    I wanna do a SQL to recoup only the rows that has duplications.
    Is this possible?
    Regards

    You can use the following to find the duplicates:
    select num_matricula matricula, cod_entid, count(*)
    from gb_recebedor_beneficio
    group by num_matricula matricula, cod_entid
    having count(*) > 1
    However, you seem to have a mismatch in your select and group by clauses in your second query. You have grb.cod_entid in your select clause and grb.cd_empresa in your group by clause. That combination will not even run without error, so what you posted must not be what you ran to get the 1430 rows, so you might want to re-check your code carefully.

  • My Laptop with Synced Firefox crashed and i had to do a fresh install, how can i retrieve all the synced data from the Mozilla Servers

    I had set up Firefox sync on my Windows 7 Laptop which crashed and I had to reinstall windows. I used to be able to share content with my Firefox synced Android too. Is there a way i can retrieve the synced data from the Mozilla servers? I tried to set up sync on my new installation on a Mac 10.6 but when i click on Set-up Sync it asks me:
    # Set-up new sync account (i already have one)
    # I already have a sync account
    When i select the second option it tells me to Add a device. I went in the "Sync Options" and tried the replace all data on this computer with my sync data, but nothing happened. When i try to connect from my Android it also asks me to add a device with the 3 boxes with letters in them.
    So in both the cases it is asking me to "Add a device" but i cannot connect to my sync account in either case to sync data from there

    Please search the forums. This has been covered here extensively.

  • How can I remove only the middle elements from a 2-D array?

    Hello all!
    We have had an issue at my work where some of our graphs featuring a Gaussian curve have an unusual rectangular distortion in the middle of the curve (sorry that I have no image to show you, the error is before my time at the company, and I've been asked to find a solution before it happens again). Basically, what should be a Gaussian curve is leveling off briefly and looking like a rounded square wave. We know what causes the distortion, so I only wish to remove the middle part, giving it the appearance of a Gaussian. It's odd, but it actually offers a good approximation of what we want. The graph is made from a 2-D array of Double values, and we can estimate the size of the leveled-area, so I figured that removing the middle elements from the graph would accomplish this. Does anybody know a way I can accomplish this?
    -Gobble
    LabView 8.5.1

    Raven,
    Thank you very much, I'll try that!
    -Gobble
    LabView 8.5.1

  • How can i fetch only the updated contacts from SQLServer to local SQLite database?

    Hi,
    I need to update my local AIR Contact application (HTML/AJAX) with the new contacts from the SQL Server (interacting with J2EE).
    How can i do it?
    Do, i have to create a background thread which Pulls (requests) data periodically, and the server response is an XML file with sql scripts? If yes, How can i do this. Is there an sample application whose source i can look at?
    Thanks.

    Hi,
    I need to update my local AIR Contact application (HTML/AJAX) with the new contacts from the SQL Server (interacting with J2EE).
    How can i do it?
    Do, i have to create a background thread which Pulls (requests) data periodically, and the server response is an XML file with sql scripts? If yes, How can i do this. Is there an sample application whose source i can look at?
    Thanks.

  • Taking the right rows from a table

    Hello, hope someone can spread som light over my issue here.
    I have a table with a number of rows. These rows are identified by a column/field (which can contain different types). For instance "Car", "Bicycle", "Moped" etc. Each type have a number of rows, where each row has a unique date (going back one year excluding holidays etc), so each type has 260 rows (about that).
    I want to take a row from two of these types with the first date in the history as an identifier (for instance 2006-09-01), then do some calculations with these two rows. After that, get one row each from the types, where the next date is used as an identfier, and so on. (Is there any keyword or something that can generate "the next date" so to speak?).
    Hope someone can help!
    regards
    Harald

    You might be right, the values I get dont correspond to another calculation I have done. For instance, for the vlaue of the date 2007-08-31, the value should be 0,1781, and it turns out to be 0,21 something...
    Here is the code:
    create or replace
    PROCEDURE convert_fx_rate_history_test AS
    fx_rate_fixed NUMBER;
    fx_rate_fixed_eur NUMBER;
    counter INTEGER;
    temp2 integer;
    i INTEGER;
    d INTEGER;
    date1 DATE;
    BEGIN
    date1 := '2006-09-01';
    temp2 := 1;
    LOOP
    SELECT fx_rate_internal
    INTO fx_rate_fixed_eur
    FROM temp_fx_rate_version2_history
    WHERE cur_cross_name = 'EUR/SEK'
    and price_date = date1;
    DBMS_OUTPUT.PUT_LINE('EUR/SEK');
    -- FOR i IN 1 .. 260
    --LOOP
    SELECT fx_rate_internal
    INTO temp2
    FROM temp_fx_rate_version2_history
    WHERE cur_cross_name = 'EUR/AUD'
    and price_date = date1;
    UPDATE temp_fx_rate_history
    SET fx_rate_internal = temp2 / fx_rate_fixed_eur
    WHERE cur_cross_name = 'EUR/AUD'
    and price_date = date1;
    --Nedan justeras så att valutaparet får SEK som bas
    UPDATE temp_fx_rate_history
    SET cur_cross_name = 'SEK/AUD'
    WHERE cur_cross_name = 'EUR/AUD'
    and price_date = date1;
    --SELECT fx_rate_internal
    -- INTO temp2
    -- FROM temp_fx_rate_version2
    --WHERE cur_cross_name = 'EUR/AUD';
    --UPDATE temp_fx_rate_history
    -- SET fx_rate_internal = temp2 / fx_rate_fixed_eur
    -- WHERE cur_cross_name = 'EUR/AUD'
    -- and price_date = date1;
    -- DBMS_OUTPUT.PUT_LINE('EUR/AUD');
    --Nedan justeras så att valutaparet får SEK som bas
    -- UPDATE temp_fx_rate_history
    -- SET cur_cross_name = 'SEK/AUD'
    -- WHERE cur_cross_name = 'EUR/AUD'
    -- and price_date = date1;
    -- DBMS_OUTPUT.PUT_LINE('SEK/AUD');
    -- DBMS_OUTPUT.PUT_LINE(date1);
    SELECT price_date
    INTO date1
    FROM temp_fx_rate_version2_history
    WHERE cur_cross_name = 'EUR/AUD' and
    price_date>date1 and rownum=1
    order by price_date asc;
    exit when date1 > '2007-08-31';
    DBMS_OUTPUT.PUT_LINE(date1);
    END LOOP;
    --COMMIT;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    --INSERT INTO empresult values(p_empno, 'Did not find Sarah Jones');
    DBMS_OUTPUT.PUT_LINE(date1);
    -- DBMS_OUTPUT.PUT_LINE(temp2);
    --DBMS_OUTPUT.PUT_LINE(fx_rate_fixed);
    END convert_fx_rate_history_test;

  • How can I get ALL the user info from WWW_FLOW_FND_USER -table?

    Hi.
    I use HTML DB authentication and therefore all my user information is stored in HTML DB tables. I can use :APP_USER to get USER_NAME, but in my application I need to have also USER_ID, FIRST_NAME, LAST_NAME and EMAIL_ADDRESS fields from database. I don't want to change any database/schema security level so I cannot read directly from WWW_FLOW_FND_USER -table when I am inside in SCOTT -schema/sec.level.
    How to read all the information?

    Thank you for your help, but I cannot find any information about backage wwv_flow_user_api on OTN or in HTML DB documentation.
    Where to start?

  • Can one find out the phone number from an apple id?

    Can somebody know my mobile  phone number if they know my imessage email address which is basically my apple id?

    Thank you wjosten. I thought as much but felt i must confirm.

Maybe you are looking for

  • Cannot access networking settings in browser

    Well, it is now December 8th, and no one has been able to tell me why I cannot access my printer's Networking information from its web page (in my case, the URL is http://192.168.2.123).  I receive the following message:   The server 192.168.2.123:80

  • Connected to Wi-Fi network, but unable to access the Internet ipad 2

    Hello, i baught a new ipad 2 32 gb , 3g.... 4.3.5os i am having an annoying issue regarding the internet connection.. where i am living i cannot connect a router so my laptop has a cable connected to it to access internet ... i had to create an ad-ho

  • Omit few items from GI print out to production (Mvt: 261)

    Hi Experts, I need to omit few items (packing items) from the print out after issuing materials against a Production order (mvt: 261). The reason is each FERT material has hundreds of components in the BOM, and the packing items are in majority. They

  • Cannot uninstall, repair, or reinstall Adobe Reader

    I think this suddenly happened a few days ago (no clue what the cause is), but since then no pdf files would have that pdf icon, they've all returned to the ugly "general file" icon, though it could still be opened with Adobe Reader. I have version 9

  • Why i don't find PREMIERE in CREATIVE CLOUD?

    why i don't find PREMIERE in CREATIVE CLOUD?