Reg : SQL for fetching 10 rows incrementaly

Hi,
Version :10.2.0.
For our development purpose we need to retrive minimum (10) records incrementaly by page wise, from table which have huge volume of data (may be 1 crore).
I tried using rownum but its not efficient ...
my query :
SELECT * FROM (SELECT ROWNUM sno,*.table_name FROM table_name) WHERE sno BETWEEN 10 AND 20
In the above, the inner query fetches all the records and the records are split based on the between clause and loaded in the grid....
Is there any other efficient query or method to get this ?
Plz advice....
TIA,

Try something like this:
select *
from (
   select t.*
   , rownum rn
   from yourtable t
   where rownum <= 20
where rn >= 10;cheers,
Anthony

Similar Messages

  • View the generated sql for fetching a repository item

    Hi guys.
    I am interested in viewing the sql that ATG framework generates to fetch a primary repository item. I would like to use this generated sql, directly on the database and avoid me the pain of having to join multiple tables to get one repository item, basically looking to avoid having to write complex sql queries to fetch information for a repository item as ATG application would view it.
    I know there is a switch somewhere to turn it on, but an example would be great. Thanks!

    Turn on the logging debug on for the repository.
    Peace
    Shaik

  • How to fetch rows from PL/SQL table(Collections)

    Hi,
    I retrived rows from the table and stored in to table type.
    Now I want fetch these rows and display on the screen. Pls guide me.
    following code is my code:
    DECLARE
    type t1 is table of emp%rowtype index by binary_integer;
    var1 t1;
    v_counter number:=0;
    BEGIN
    select * bulk collect into var1 from emp;
    for vr in var1.first..var1.last
    loop
    dbms_output.put_line(var1(1)); --Got an Error Here. Acually I don't Know how to  fetch.
    update dept set deptno=var1.deptno --Here also Error occured.
    end loop;
    END;

    Fetching rows to display them is a task for the client tool. You need to define a ref cursor therefore.
    If you just want to play around, here we go
    SQL> DECLARE
      2    type t1 is table of emp%rowtype index by binary_integer;
      3    var1 t1;
      4    v_counter number:=0;
      5  BEGIN
      6    select * bulk collect into var1 from emp;
      7    for vr in 1..var1.count loop
      8      dbms_output.put_line(var1(vr).ename);
      9      update dept set deptno=var1.deptno Here also Error occured.
    10    end loop;
    11  END;
    12  /
    SCOTT
    ADAMS
    PL/SQL procedure successfully completed.
    SQL>

  • For each row of a table call a pl/sql function

    Hi,
    i have a search form in adf like this:
    parameter1:___
    parameter2:____
    buttonSearch
    Table with results
    field1 field2 field3
    row1 ------ --------- -------
    row2 ------ --------- -------
    row3 ------ --------- -------
    The user inputs the parameters 1 and 2 then press buttonSearch and the query execute and returns rows 1 to 3.
    What i need is for each row call pl/sql function and passed the parameter 1 and 2 and field 1 to 3 (plsql function recives 5 parameters (parameter1, parameter2, field1 , field2 and field3) )
    my buttonSearch call a java class that execute ExecuteWithParamters method.
    I create the call to my plsql function on Application module class and then export as a java interface.
    So i have the function to use in the viewcontroller layer, but i don't know where to use it, and how to pass the paramters: the parameter 1 and 2 that user inputs and the row fields.....
    any ideas....
    thanks!!

    Hi,
    for this you need to call the PLSQL function upon table rendering, which means that you need a field in the table referencing a managed bean. In the managed bean you can use #{row} and resolve it using a ValueExpression. #{row} gives you access to the current rendered row (this is why you need to do it when the table renders) and thus allows you to call getAttribute(name) to get the values of field 1 - 3. The search field value you should get through the bindings reference (assuming the search form uses ADF). Then you create an operation binding for the executeWithParameters and call operationBindingName.getParamsMap().put(argname, argvalue); on it.
    Frank
    Ps.: I am concerned about the performance you get and wonder if it isn't possible to create a transient attribute that executes the function and displays the results. As I understand, the search parameters are only to filter the result set, which you still can do

  • SQL merge and after insert or update on ... for each row fires too often?

    Hello,
    there is a base table, which has a companion history table
    - lets say USER_DATA & USER_DATA_HIST.
    For each update on USER_DATA there has to be recorded the old condition of the USER_DATA record into the USER_DATA_HIST (insert new record)
    - to have the history of changes to USER_DATA.
    The first approach was to do the insert for the row trigger:
    trigger user_data_tr_aiu after insert or update on user_data for each rowBut the performance was bad, because for a bulk update to USER_DATA, there have been individual inserts per records.
    So i tried a trick:
    Instead of doing the real insert into USER_DATA_HIST, i collect the USER_DATA_HIST data into a pl/sql collection first.
    And later i do a bulk insert for the collection in the USER_DATA_HIST table with stmt trigger:
    trigger user_data_tr_ra after insert or update on user_dataBut sometimes i recognize, that the list of entries saved in the pl/sql collection are more than my USER_DATA records being updated.
    (BTW, for the update i use SQL merge, because it's driven by another table.)
    As there is a uniq tracking_id in USER_DATA record, i could identify, that there are duplicates.
    If i sort for the tracking_id and remove duplicate i get exactly the #no of records updated by the SQL merge.
    So how comes, that there are duplicates?
    I can try to make a sample 'sqlplus' program, but it will take some time.
    But maybe somebody knows already about some issues here(?!)
    - many thanks!
    best regards,
    Frank

    Hello
    Not sure really. Although it shouldn't take long to do a test case - it only took me 10 mins....
    SQL>
    SQL> create table USER_DATA
      2  (   id      number,
      3      col1    varchar2(100)
      4  )
      5  /
    Table created.
    SQL>
    SQL> CREATE TABLE USER_DATA_HIST
      2  (   id      number,
      3      col1    varchar2(100),
      4      tmsp    timestamp
      5  )
      6  /
    Table created.
    SQL>
    SQL> CREATE OR REPLACE PACKAGE pkg_audit_user_data
      2  IS
      3
      4      PROCEDURE p_Init;
      5
      6      PROCEDURE p_Log
      7      (   air_UserData        IN user_data%ROWTYPE
      8      );
      9
    10      PROCEDURE p_Write;
    11  END;
    12  /
    Package created.
    SQL> CREATE OR REPLACE PACKAGE BODY pkg_audit_user_data
      2  IS
      3
      4      TYPE tt_UserData        IS TABLE OF user_data_hist%ROWTYPE INDEX BY BINARY_INTEGER;
      5
      6      pt_UserData             tt_UserData;
      7
      8      PROCEDURE p_Init
      9      IS
    10
    11      BEGIN
    12
    13
    14          IF pt_UserData.COUNT > 0 THEN
    15
    16              pt_UserData.DELETE;
    17
    18          END IF;
    19
    20      END;
    21
    22      PROCEDURE p_Log
    23      (   air_UserData        IN user_data%ROWTYPE
    24      )
    25      IS
    26          ln_Idx              BINARY_INTEGER;
    27
    28      BEGIN
    29
    30          ln_Idx := pt_UserData.COUNT + 1;
    31
    32          pt_UserData(ln_Idx).id     := air_UserData.id;
    33          pt_UserData(ln_Idx).col1   := air_UserData.col1;
    34          pt_UserData(ln_Idx).tmsp   := SYSTIMESTAMP;
    35
    36      END;
    37
    38      PROCEDURE p_Write
    39      IS
    40
    41      BEGIN
    42
    43          FORALL li_Idx IN INDICES OF pt_UserData
    44              INSERT
    45              INTO
    46                  user_data_hist
    47              VALUES
    48                  pt_UserData(li_Idx);
    49
    50      END;
    51  END;
    52  /
    Package body created.
    SQL>
    SQL> CREATE OR REPLACE TRIGGER preu_s_user_data BEFORE UPDATE ON user_data
      2  DECLARE
      3
      4  BEGIN
      5
      6      pkg_audit_user_data.p_Init;
      7
      8  END;
      9  /
    Trigger created.
    SQL> CREATE OR REPLACE TRIGGER preu_r_user_data BEFORE UPDATE ON user_data
      2  FOR EACH ROW
      3  DECLARE
      4
      5      lc_Row      user_data%ROWTYPE;
      6
      7  BEGIN
      8
      9      lc_Row.id   := :NEW.id;
    10      lc_Row.col1 := :NEW.col1;
    11
    12      pkg_audit_user_data.p_Log
    13      (   lc_Row
    14      );
    15
    16  END;
    17  /
    Trigger created.
    SQL> CREATE OR REPLACE TRIGGER postu_s_user_data AFTER UPDATE ON user_data
      2  DECLARE
      3
      4  BEGIN
      5
      6      pkg_audit_user_data.p_Write;
      7
      8  END;
      9  /
    Trigger created.
    SQL>
    SQL>
    SQL> insert
      2  into
      3      user_data
      4  select
      5      rownum,
      6      dbms_random.string('u',20)
      7  from
      8      dual
      9  connect by
    10      level <=10
    11  /
    10 rows created.
    SQL> select * from user_data
      2  /
            ID COL1
             1 GVZHKXSSJZHUSLLIDQTO
             2 QVNXLTGJXFUDUHGYKANI
             3 GTVHDCJAXLJFVTFSPFQI
             4 CNVEGOTDLZQJJPVUXWYJ
             5 FPOTZAWKMWHNOJMMIOKP
             6 BZKHAFATQDBUVFBCOSPT
             7 LAQAIDVREFJZWIQFUPMP
             8 DXFICIPCBCFTPAPKDGZF
             9 KKSMMRAQUORRPUBNJFCK
            10 GBLTFZJAOPKFZFCQPGYW
    10 rows selected.
    SQL> select * from user_data_hist
      2  /
    no rows selected
    SQL>
    SQL> MERGE
      2  INTO
      3      user_data a
      4  USING
      5  (   SELECT
      6          rownum + 8 id,
      7          dbms_random.string('u',20) col1
      8      FROM
      9          dual
    10      CONNECT BY
    11          level <= 10
    12  ) b
    13  ON (a.id = b.id)
    14  WHEN MATCHED THEN
    15      UPDATE SET a.col1 = b.col1
    16  WHEN NOT MATCHED THEN
    17      INSERT(a.id,a.col1)
    18      VALUES (b.id,b.col1)
    19  /
    10 rows merged.
    SQL> select * from user_data_hist
      2  /
            ID COL1                 TMSP
             9 XGURXHHZGSUKILYQKBNB 05-AUG-11 10.04.15.577989
            10 HLVUTUIFBAKGMXBDJTSL 05-AUG-11 10.04.15.578090
    SQL> select * from v$version
      2  /
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE    10.2.0.4.0      Production
    TNS for Linux: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - ProductionHTH
    David

  • How to force SQL*Loader to assign the same SYSDATE for all rows?

    I want to use SQL*Loader to load some rows and a "SYSDATE" generated column, but making sure this date is THE SAME for all rows. I have seen that if I load HUNDREDS of rows there is a little difference between them (in terms of seconds). I guess it is "the moment each row entered the DB", but I need the same value for all rows (preferably, "the moment SQL*Loader was launched"). Is there any way to achieve this?
    Thank you very much.

    Hello user2393320.
    Given some thought, using a date value to identify all records from a single load isn't very wise.
    Are you able to create a procedure on the database that could be executed during SQL*Loader's execution? If so, you could develop the procedure to take in the record number of the row being loaded as an input parameter and output this unique date value for all rows loaded. The procedure would need to store the date value in a table when the first row is being loaded and return the stored date value as its output. This obviously assumes that only one sqlldr session is running at any time.
    I highly recommend using a numeric sequence in the control file instead of a date to identify each file load:
    , file_load_seq SEQUENCE(MAX, 1)
    Another approach would be to load the record number being loaded in addition to the sysdate:
    , record_number RECNUM
    Hope this helps,
    Luke

  • ORA-01423: error encountered while checking for extra rows in exact fetch

    ERROR at line 1:
    ORA-01423: error encountered while checking for extra rows in exact fetch
    ORA-01722: invalid number
    ORA-06512: at "Department.get_emp_name", line 57
    ORA-06512: at line 14
    Hi
    The above are the error messages I am running into and I am not sure what it means at all. I do have a query which select few rows into cursor
    cursor c_requested is
    select * from departments where emp_id in (1, 2, 3)
    now from these rows I again creating a query dynamically
    open c_requested;
    loop
    fetch c_requested into deptID, name, authorized; -- declared variables
    exit when c_requested%NotFound;
    sqlstring := 'Select name from employees where deptID = ' || deptID || ' and Authorized = ' || authorized;
    begin
    execute immediate sqlstring into description; -- declared variable
    exit;
    exception when no_data_found then
    description := 'FILTER_OUT';
    end;
    end loop;
    close c_requested;
    This code is inside a function get_emp_name(). When I execute this function I am getting the above errors. I really appreciate all your help. Please let me know if you need more information.
    Thank you very much

    Thank you very much damorgan,
    I looked through my code and figured out what was wrong. I had a varchar2 column in the table where I was passing a value 999 instead of '999'. Thanks again.
    I have one more question. I am using cursor to loop through.. here is my code
    rowcount integer;
    cursor c_emp is
    select * from employees where empID in (....);
    begin
    open c_emp;
    rowcount := c_emp%RowCount;
    loop
    end loop;
    dbms_output.put_line(rowcount);
    end;
    I am getting rowcount = 0 even though there are many values in it. I am not sure if I am using the where clause properly. Any help would be appreciated.
    thank you.

  • Update button in sql report for each row can only get the report value

    I have to added Update for each row of records like:
    select a.*,'Update' button from (
    select c.*,d.login from country c,champ d
    where c.champ_id=d.champ_id(+)
    order by c.name) a
    then go to the report->edit button ->Column Link
    I added some items P40_REGION, P40_CHAMPID,P40_ACTIVE,P40_CODE and assign the value like #region#,#active# ,#code# to these item, but when I click the update button in the report I found the values such as #region#,#active# ,#code# is the report value not the select list selected value(the region, active column are displayed as select list lov).
    Can anyone tell me how to sort this knid of problem?
    Thanks a lot!

    Sorry, it doesn't work. I also tried apex_application.g_f01(i), but not everytime I can get the value or get the incorrect value. If you have time you can try to create it like what I have described. Our team use two days now but still can not sort this problem.

  • Problem in fetching row code...

    Hi there,
    I have a bit of a problem setting up automatic row processing. The Apex processing is causing an error, but I'm not sure what PL/SQL code is being run (obviously, I don't have access to the Apex code) and all I get is the error following:
    0.03: Processing point: AFTER_HEADER
    0.03: ...Process "Fetch Row from VMS2_VU_VEHICLE_DETAILS": DML_FETCH_ROW (AFTER_HEADER) F|#OWNER#:VMS2_VU_VEHICLE_DETAILS:P21_ID:ID
    0.05: Show ERROR page...
    0.05: Performing rollback...
    0.05: Processing point: AFTER_ERROR_HEADER
    and then the following exception report on the page:
    ORA-06550: line 1, column 17: PL/SQL: ORA-00936: missing expression ORA-06550: line 1, column 9: PL/SQL: SQL Statement ignored
    Can anyone tell me how I can diagnose the problem?
    please ,
    Thanks in Advance
    Ahmed ,

    Go to apex.oracle.com, use the Request a Workspace link, submit a request, wait for approval, then import your app into your workspace.
    Create a table in your workspace schema using the SQL Workshop so that you can get the same error message when you run that form page that's giving you trouble.
    When you get to that point, just tell me your workspace name and application ID.
    Scott

  • Qry return same value for a particular column for each row but not all time

    hi,
    We recently migrated to Oracle Database 10.2.0.3.0 from 9i. We were using a sql to populate a table and it had been running fine. After migration the same sql is fetching / population incorrect values, but not everytime. If we run the same sql again it gives a correct result.
    Ex:
    insert into a1 ( col1, col2, col3 )
    select a.field1, b.field2, c.field
    from tab1 a, tab2 b, tab3 c
    where a.field = b.field
    and b.field (+) = c.field
    something like this. Let us assume it fetches 200 rows
    But sometimes the col1 has the same value for all the 200 rows and col2, col3 has correct values. If we run the same sql next time, the col1 fetches the correct value and everything is correct.
    Could someone help on the above issue.

    I know it's difficult but can you put together a small test case for us to reproduce this behaviour? Did you contact Oracle Support?
    Any special constructs used behind the scenes? Virtual private database? Views?Materialized Views? Anything else?

  • Partial locking for a row

    Hello,
    For example, I have two queries, the first one just accesses
    the first entry of the row. And the second one just accesses the
    second entry of the row.
    Is there any locking method ? Such that I can lock the first
    entry of the row when I use the first query and lock the second
    entry of the row when I use the second query. So that I can
    speed up the performance of my system in this way.
    null

    If you're trying to lock on a per-column basis, you won't be able
    to, since locks are granular to a per-row basis, not below.
    If you want to lock a specific row on a table, you may use a
    2-phase commit method like so:
    EXEC SQL
    SELECT A.ROWID, B.ROWID, <rest of rowid's>, <rest of data>
    INTO :blabla, :blabla,.....
    FROM TEST_TABLE_1 A, TEST_TABLE_2 B, <rest of tables>
    WHERE <where clause w/joins, etc...>
    FOR UPDATE;
    This will acquire row-locks on all tables referenced, for all
    rows fetched by the SELECT.
    This lock will be released when you close the current transaction
    with a COMMIT or a ROLLBACK (or, if using from within a cursor,
    when the cursor is closed if your configuration is set this way).
    That means that you would:
    1) Acquire the locks on all the rows
    2) Do all your work using the ROWID's to locate the rows to query
    or manipulate (while they're locked)
    3) Commit or rollback
    This will allow you to use row-level locks, which increases
    concurrency and makes the SQL code a lot faster (because of the
    use of rowid's).
    I've found that the best method to do this is to use a cursor,
    and then work on that cursor's fetches using the ROWID's (NOT the
    WHERE CURRENT OF CLAUSE when there is more than one table
    involved in the lock mechanism).
    Best
    Diego
    Stephen Lee (guest) wrote:
    : Hello,
    : For example, I have two queries, the first one just
    accesses
    : the first entry of the row. And the second one just accesses
    the
    : second entry of the row.
    : Is there any locking method ? Such that I can lock the
    first
    : entry of the row when I use the first query and lock the second
    : entry of the row when I use the second query. So that I can
    : speed up the performance of my system in this way.
    null

  • Raise expection for each row if returned set contains x

    Hello Guys,
    I have the following code and almost gave up on the idea to raise an exception and print
    a line for each row where the sales price is < 10. I know how this works with a CURSOR but I want to try it without it. Thinking about it let me to the conclusion that this is not possible to act on individual row results on a set based operation. I will have to use a CURSOR (not set based so I can look at each row).
    Am I thinking correctly?
    (Code example deleted due to confusion)
    Code example deleted due to confusion
    Edited by: metalray on 10.11.2010 01:07

    Hi 3360,
    I am using PL/SQL. I can make my point without any code.
    The question, in a different format is this:
    Can I throw an whatever exception (or dbms_output put line) for individual rows WITHOUT using a cursor.
    My answer (and I just need clarification on this):
    *(1)* No, because anything apart from a cursor is set-based and set-based operations (select, join, union)
    can not through exceptions on individual rows.
    *(2)* Yes, you can have a DBMS_OUTPUT.PUT_LINE with whatever exception on a set based operation
    for each individual row that causes the exception (I dont think this answer is true :)
    @Agustin UN, thanks for that. I know that is possible :) The problem is,
    that I dont think I can print or fetch each individual row that causes the "exception" since
    it is treated as a set. - I am welcome for someone to tell me that it work nevertheless

  • 'Fetched Rows' refresh issue

    When freezing views for several tables, the 'Fetched Rows' value is always the last updated value, not the correct one in the current context.
    In the case of finding the total number of rows there is a workaround - to select from the popup menu Table > Count rows, but then, why display an incorrect value ?
    And on the same 'count rows' topic, why do I need to further press the 'Apply' button in order to get the rows numbered ?
    Tudor

    You are right - the last fetch performed by Raptor/SQL Developer updates the fetch count on the status bar (this includes things like querying the columns when displaying a table tab).
    I have suggested previously that we have the fetch count displayed next to the query execution time on the SQL Worksheet, but haven't had any positive response.
    There doesn't appear to be enough room on the data tab for this to be displayed in the same place when querying table/view data from the table/view tab.
    As for the 'Count Rows' needing Apply - even if you don't want to, you are given the option of copying the query that is being used for the Count Rows (not that I think this means we should have the two step process for counting rows).

  • Return Code - Query for Multiple Rows as XML

    Hi,
    I'm executing an MSSQL stored procedure through the "Query for Multiple Rows as XML" activity in LiveCycle ES. I do this through a call statement such as this:
    { call MyStoredProc(?) }
    This works great, the stored procedure always returns a record set (with or without records). I use this activity rather than "Call Stored Procedure" because I can transform the record set into XML right away within this activity. Unfortunately any exception arising from invoking this stored procedure cannot be handled within the workflow as this activity does not have an exception handler (lightning bolt). In an attempt to handle at least some exceptions we have decided to use try/catches within the stored procedures and return different error codes. Now the problem I am faced with is that there is no way to retrieve the returned code within any of the SQL activities. We don't want to have to write an execute script for each of these SQL calls. Is there any way to do this? Seems like I'm 95% there.
    Thanks
    Nic

    Thanks for the offer, unfortunately we would need something certified by Adobe.
    Nic

  • Prompting user for input for each row in the report

    Is it possible to have a user entered field for each row in a report ?
    ie. have a report with empolyee number, employee name, title, salary, and comment. Select of of these columns from the SQL query except for the comment, and then when the report is generated have the user be prompted for what the want the comment to be for every employee in the report?

    That is, have the user generating the report enter in a different comment for EACH employee. (ie Joe Smith's comment is "good worker and John Smith's comment is "come to work late on Tuesdays and Thursdays", Sally Jones' comment is "Expert in C++" etc.) as the reports is being built for each row returned from the query.

Maybe you are looking for

  • Loading FF4 wiped out a large number of tabs, how do I restore?

    I thought I was loading a security update. WHAT?! ALL MY TABS I WAS USING ARE WIPED OUT? Really? Or have you added a way to restore them? Apparently the default setting on FF4 is to destroy the preserved tabs during the update. My browser had a large

  • External charger for Zen V p

    I have a new Zen V Plus, and purchased an external USB charger from Hama. Apparently this does not work. The charging indicator does not show up, and there is no sign of increased battery charge. Is there any reason why this does not work, or is ther

  • Change in material valuation- MAP

    Hello, When I change the valuation of a material with price control MAP in the T. Code MR21, the system creates accounting, controlling and profit centre documents. But the system does not change the price in the material master in the current valuat

  • Workflow skipping some lines

    Hi dudes, I hav created a Workflow. Which also calls some rules. I have executed it from admin interface by clicking on 'Run Tasks' tab. It worked fine in the beginning. But after some time the workflow started executing only few lines inside a block

  • Maximum symbols in flash

    does anyone know if theres a maximum amount of symbols that can be created in a flash library file? or is there no limitation to the number of symbols possible?