Select a range of rows to be displayed using ROWNUM

I am trying to select a range of records to be displayed using Rownum
It works using MINUS
SQL> select rownum,department_id,department_name from departments where rownum <= 20
minus
select rownum,department_id,department_name from departments where rownum < 11;
but does not work if a range is specified
select rownum,department_id,department_name from departments where rownum >= 11 and rownum <= 20;
What has gone wrong?
Details of what I have tried are as follows:
Connect to the sample schema HR
SQL> connect hr/hr
SQL> desc departments
Name Null? Type
DEPARTMENT_ID NOT NULL NUMBER(4)
DEPARTMENT_NAME NOT NULL VARCHAR2(30)
MANAGER_ID NUMBER(6)
LOCATION_ID NUMBER(4)
List all records in Departments
SQL> select rownum,department_id,department_name from departments;
ROWNUM DEPARTMENT_ID DEPARTMENT_NAME
1 10 Administration
2 20 Marketing
3 30 Purchasing
4 40 Human Resources
etc......
26 260 Recruiting
27 270 Payroll
27 rows selected.
List the first 10 records in DEPARTMENTS
SQL> select rownum,department_id,department_name from departments where rownum <= 10;
ROWNUM DEPARTMENT_ID DEPARTMENT_NAME
1 10 Administration
2 20 Marketing
etc.....
10 100 Finance
List row number from 11 to 20, but cannot no rows selected. Why?
SQL> select rownum,department_id,department_name from departments where rownum >= 11 and rownum <= 20;
no rows selected
Use of MINUS can retrieve row number from 11 to 20
SQL> select rownum,department_id,department_name from departments where rownum <= 20
minus
select rownum,department_id,department_name from departments where rownum < 11;
ROWNUM DEPARTMENT_ID DEPARTMENT_NAME
11 110 Accounting
12 120 Treasury
13 130 Corporate Tax
14 140 Control And Credit
15 150 Shareholder Services
16 160 Benefits
17 170 Manufacturing
18 180 Construction
19 190 Contracting
20 200 Operations
10 rows selected.

For each row returned by a query, the ROWNUM pseudocolumn returns a number indicating the order in which Oracle selects the row from a table or set of joined rows. The first row selected has a ROWNUM of 1, the second has 2, and so on.
Conditions testing for ROWNUM values greater than a positive integer are always false. For example, this query returns no rows:
SELECT * FROM employees
WHERE ROWNUM > 1;
You can get the selected records based on the rownum using the inline query....
SQL> select rownum, empno from emp;
ROWNUM EMPNO
1 7369
2 7499
3 7521
4 7566
5 7654
6 7698
7 7782
8 7788
9 7839
10 7844
11 7876
ROWNUM EMPNO
12 7900
13 7902
14 7934
14 rows selected.
SQL> select * from (select rownum rn, empno from emp) where rn > 2 and rn < 5;
RN EMPNO
3 7521
4 7566

Similar Messages

  • How do I select a range of rows from an internal table in the debugger?

    Hi,
    I have a case where I wanted to delete a range of rows (several thousand) from an internal table using the debugger.
    It seems that rows can only be selected one at a time by selecting (clicking) on the far left side of the row.
    This is cumbersome, if not impossible when wishing to delete several thousand rows. 
    Other tools, such as Excel for example, allow for selecting a range of rows by selecting the first row and then holding the SHIFT key and selecting the last row and all rows in between will be selected.
    I can't seem to find the combination of keys that will allow this in the table (or structure) tab of the debugger.
    Is it possible to select a range of rows without having to select each row one at a time?
    Thanks for your help,
    Andy

    While it's a Table Control and should/could have a button to select all fields (or visible fields)...I don't think we can do it right now...I know it's a pain to select each row one at a time...but I don't we have any more options...
    Greetings,
    Blag.

  • Can I simulate SELECT * FROM TABLE WHERE ROW IN (1111,2222) using SQLJ

    I have a fct like
    public void fct(String inStr) {
    String str = "SELECT * FROM TABLE WHERE ROW IN" + inStr;
    // then I xecute the query using JDBC connection
    But I want to do the same thisn using SQLJ like:
    public void fct(String inStr) {
    #sql [nctx] iter = { SELECT * FROM TABLE WHERE ROW IN :inStr}
    When I run the second version and give a parameter like "(1111,2222)" it gives
    ORA-01722: invalid number error.
    Is there a way to give parameters to in clauses of SQLJ statements.
    Thanks in regard.

    This is a SQLJ FAQ. You can find the FAQ at:
    http://technet.oracle.com/tech/java/sqlj_jdbc/htdocs/faq.html
    Your question is addressed in the following section:
    http://technet.oracle.com/tech/java/sqlj_jdbc/htdocs/faq.html#variablesizevaluelist
    Note that that section has a typo. The lines:
    ? // populate mynumbers
    #sql { SELECT * FROM tab WHERE col in (:(a[0]),:(a[1]),?};
    should read:
    ... // populate mynumbers
    #sql { SELECT * FROM tab WHERE col in (:(a[0]),:(a[1]),...};
    By the way, with the next release SQLJ will support pasting in of dynamic SQL fragments. Then you'll be able to do pretty much what you are trying to accomplish here (albeit with slightly different syntax). Until then you'd have to use the workarounds from the FAQ.

  • Select a range of rows?

    I know I can edit SELECT TOP (200) to increase rows, but how can I select NEXT 200 rows or rows 200 thru 400? I have tried OFFSET, START AT, SKIP, etc.

    Of course.
    you can create a stored procedure like this
    create PROCEDURE [dbo].[usp_GetPersons]
    @rowsperpage int = 200
    , @pagenumber int = 1
    AS
    BEGIN
    SET NOCOUNT ON;
    ;with cte
    as (
    SELECT *, ROW_NUMBER() OVER (ORDER BY [BusinessEntityID]) AS RowNumber
    FROM [Person].[Person]
    select
    from
    cte
    WHERE RowNumber BETWEEN ((@PageNumber-1)*@RowsPerPage)+1
    AND @RowsPerPage*(@PageNumber)
    SET NOCOUNT OFF;
    END
    and after that you can execute
    EXEC [dbo].[usp_GetPersons] @rowsperpage = 200, @pagenumber = 1
    go
    with this results
    and so on
    EXEC [dbo].[usp_GetPersons] @rowsperpage = 200, @pagenumber = 2
    go
    I hope this will help you
    P. Ceglie - "CIA - Is the main thing" ______________________________________________ Se alcuni post rispondono al tuo quesito(non necessariamente i miei), ricorda di contrassegnarli come risposta e non dimenticare di contrassegnare anche i post
    utili. La community ringrazia :-)

  • Restricting number of rows in EJB  QL    using rowNum or rowId

    Hii Javaites
    I am using EJB finder methods to get a a list of records from database.
    Now i want that only particular number of records should be fetched.
    For tht i want 2 use rownum or rowId.
    Can anyone plz tell me can we do tht in EJB QL.
    I m using Weblogic 8

    shouldn't use rownum or rowid to do such a thing.
    %

  • I still have a problem clearing history and i did select time range to Everything

    I still have a problem clearing history and i did select time range to "Everything". I tested using Internet explorer and I could clear the history there so its not a problem with the Xp secondary account. I even disabled the add ons in firefox and still get the same issue

    sorry, scratch this, the first post did enable me to find a solution, it was the signon.sqlite file that had become corrupted.
    As an interesting aside, this has also fixed the problem with using Xmarksspace which was giving me an "error 3" synchronising problem.
    Apologies for the tone of my previous posting, you did provide the information that enabled me to find a solution, thank you and sorry.
    Regards
    Crashhot

  • Display range of rows

    Can anyone suggest me an efficent SQL which can return range of rows for example I want to display records with rownum>=20 and rownum<=40.

    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Uma Santharam:
    Can anyone suggest me an efficent SQL which can return range of rows for example I want to display records with rownum>=20 and rownum<=40. <HR></BLOCKQUOTE>
    Hi,
    You can not use equal to and greater then condition in rownum.
    Secondly if you want 20 and 40 to be included in range search then use rownum <21
    and rownum < 41.
    Try to use following query to solve your above said problem.
    select e1.empno from emp e1
    where rownum <10 and empno not in
    ( select e1.empno from emp e1 where rownum <5);
    null

  • Dynamic Select Options/Ranges Maintain and Display in my screen

    Hi I am trying to figure out if I can create a screen which will will read various select-options I have stored in a custom table but am having trouble finding something which will allow me to display each of 'select-options' in my dynpro... has anyone ever done this?
    I'd rather not reinvent the wheel or mimic - does anyone know of a way to basically use a loaded range and display it on a screen for display or maintenance using standard SAP routines/classes?
    Thanks in advance!
    Roc..

    @Adrian - I got your email regarding the code sample, here is a quick example of how to popup a dynamic selection for up to 5 tables...
    *& Report  ZRS_DYNAMIC
    REPORT  zrs_dynamic.
    * START Dynamic Range Selection Definitions
    * Definition of the selection_if variable, which is used to reference
    * the selections obtained
    DATA: gv_selid TYPE rsdynsel-selid.
    * Definition of the TABLES_TAB table for use in providing the list of
    * fields available for creating select options from
    DATA: gt_tables TYPE STANDARD TABLE OF rsdstabs.
    DATA: gs_tables TYPE rsdstabs.
    PARAMETERS: p_tab1 TYPE tabname DEFAULT 'KNA1',
                p_tab2 TYPE tabname DEFAULT 'KNB1',
                p_tab3 TYPE tabname DEFAULT 'KNC1',
                p_tab4 TYPE tabname DEFAULT 'KNVV',
                p_tab5 TYPE tabname DEFAULT 'KNVP'.
    START-OF-SELECTION.
      gs_tables-prim_tab = p_tab1 .APPEND gs_tables TO gt_tables.
      gs_tables-prim_tab = p_tab2 .APPEND gs_tables TO gt_tables.
      gs_tables-prim_tab = p_tab3 .APPEND gs_tables TO gt_tables.
      gs_tables-prim_tab = p_tab4 .APPEND gs_tables TO gt_tables.
      gs_tables-prim_tab = p_tab5 .APPEND gs_tables TO gt_tables.
    * Definition of Table which includes the select-option range for field
      TYPES: ty_selopt_t TYPE  rsdsselopt OCCURS 10.
    * Definition of field name and select option range table
      TYPES: BEGIN OF ty_frange,
               fieldname TYPE rsdstabs-prim_fname,
               selopt_t TYPE ty_selopt_t,
             END OF ty_frange.
      TYPES: ty_frange_t TYPE ty_frange OCCURS 10.
      TYPES: BEGIN OF ty_range,
               tablename LIKE rsdstabs-prim_tab,
               frange_t TYPE ty_frange_t,
             END OF ty_range.
      TYPES: ty_range_t TYPE STANDARD TABLE OF ty_range.
      DATA: it_ranges TYPE ty_range_t.
    * work areas
      DATA: gs_ranges TYPE ty_range.
      DATA: gs_frange TYPE ty_frange.
      DATA: gs_selopt TYPE rsdsselopt.
      DATA: gt_ranges TYPE ty_range_t.
      DATA: gt_frange TYPE ty_frange_t.
      DATA: gt_selopt TYPE ty_selopt_t.
    * Definition of the fields list avaiable
      TYPES: ty_fields TYPE STANDARD TABLE OF rsdsfields.
      DATA: it_fields TYPE ty_fields.
      DATA: gs_fields TYPE rsdsfields.
    * END Dynamic Range Selection --------------------------------------------
      CALL FUNCTION 'FREE_SELECTIONS_INIT'
        EXPORTING
          kind         = 'T'
        IMPORTING
          selection_id = gv_selid
        TABLES
          tables_tab   = gt_tables.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
      CALL FUNCTION 'FREE_SELECTIONS_DIALOG'
        EXPORTING
          selection_id    = gv_selid
          title           = 'Select WHERE criteria for Rule'(s12)
          as_window       = 'X'
          start_row       = 7
          start_col       = 10
        IMPORTING
          field_ranges    = it_ranges
        TABLES
          fields_tab      = it_fields
        EXCEPTIONS
          internal_error  = 1
          no_action       = 2
          selid_not_found = 3
          illegal_status  = 4
          OTHERS          = 5.
    Edited by: Rocco Scocco on Jun 17, 2010 3:48 PM
    Edited by: Rocco Scocco on Jun 17, 2010 3:49 PM

  • Select Color Range, fails v13.1.1 on Retina Display Mac

    Is there a trick to getting the new Color Range selection function to work on a retina Mac Book Pro?
    I am quite familiar with the color range selection in the previous version of Photoshop, and used it regularly. I've decided to try as simply as possible by using a flat image (no layers), and trying to select colors. I've increased the contrast in the image to make darks and lights much easier to pull out.
    I've explored setting the sample size to point-sample up to 3x3, and 5x5. I've also set the resolution of my display to 2880 x 1800 (to reduce the possiblility of anti-aliasing problems).
    It will not make any selection though, using the eye-dropper sample.
    Using other options will work, such as Highlights, Shadows, Skin Tones, etc., but it won't do anything with Sampled Colors.

    SO very glad I'm not the only one with this seemingly EXACT same issue.
    System:
    Photoshop CS6 via Creative Cloud membership.
    Windows 7 Home Premium
    16GB Ram
    Issue:
    Select > Color Range used to work perfectly before update 13.1.1
    Now since the update 13.1.1 Color Range doesn't do jack properly. Selecting any color doesn't do anything. sometimes if I select a white it will act as though I've pulled out a gray.. but even one pixel difference will make it deselect. This only happens with Sampled Colors. All otehr color range preselections work as advertised. This would be great if I didn't need the precision afforded to me with Sampled Colors. This is mission critical to my daily work as a scren printing artist and have been unable to find a succesful workaround.
    Is there at least a way (without having to uninstall/reinstall) to downgrade back to 13.0.x until this bug is found and fixed?

  • Devloped an ALV report for daily cash receipts for selected date range

    hi,   
                 how to devlop an ALV report for daily cash receipts for selected date range.for this report what are the tables and fields we have to use.what is the selectionscreen&what is logic.give me sample report.

    Hi,
    You can develop simple reports using Report Painter.
    You may be also interested in:
    Check report SAPMF05A for credit memo
    See the following Std reports on Payment Advices execute the Tcodes:
    S_ALR_87009888
    S_ALR_87009889
    S_ALR_87009890
    S_ALR_87009891
    S_ALR_87009892
    S_ALR_87009893
    S_ALR_87009978
    S_ALR_87009979
    S_ALR_87009980
    S_ALR_87009981
    S_ALR_87009982
    S_ALR_87009983
    S_ALR_87010056
    S_ALR_87010057
    S_ALR_87010058
    S_ALR_87010059
    S_ALR_87010060
    S_ALR_87010061
    S_ALR_87010066
    S_ALR_87010067
    S_ALR_87012106
    S_ALR_87012107
    S_ALR_87012108
    S_ALR_87012109
    S_ALR_87012110
    S_ALR_87012111
    S_ALR_87012116
    S_ALR_87012117
    S_ALR_87012200
    S_ALR_87012201
    S_ALR_87012202
    S_ALR_870122
    S_ALR_87012204
    S_ALR_87012205
    S_ALR_87012350
    S_ALR_87012351
    S_ALR_87012352
    S_ALR_87012353
    S_ALR_87012354
    S_ALR_87012355
    sample ALV report:
    tables:
    marav. "Table MARA and table MAKT
    Data to be displayed in ALV
    Using the following syntax, REUSE_ALV_FIELDCATALOG_MERGE can auto-
    matically determine the fieldstructure from this source program
    Data:
    begin of imat occurs 100,
    matnr like marav-matnr, "Material number
    maktx like marav-maktx, "Material short text
    matkl like marav-matkl, "Material group (so you can test to make
                            " intermediate sums)
    ntgew like marav-ntgew, "Net weight, numeric field (so you can test to
                            "make sums)
    gewei like marav-gewei, "weight unit (just to be complete)
    end of imat.
    Other data needed
    field to store report name
    data i_repid like sy-repid.
    field to check table length
    data i_lines like sy-tabix.
    Data for ALV display
    TYPE-POOLS: SLIS.
    data int_fcat type SLIS_T_FIELDCAT_ALV.
    select-options:
    s_matnr for marav-matnr matchcode object MAT1.
    start-of-selection.
    read data into table imat
      select * from marav
      into corresponding fields of table imat
      where
      matnr in s_matnr.
    end-of-selection.
    Now, we start with ALV
    To use ALV, we need a DDIC-structure or a thing called Fieldcatalogue.
    The fieldcatalouge can be generated by FUNCTION
    'REUSE_ALV_FIELDCATALOG_MERGE' from an internal table from any
    report source, including this report.
    The only problem one might have is that the report and table names
    need to be in capital letters. (I had it )
    Store report name
    i_repid = sy-repid.
    Create Fieldcatalogue from internal table
      CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
           EXPORTING
                I_PROGRAM_NAME         = sy-repid
                I_INTERNAL_TABNAME     = 'IMAT'  "capital letters!
                I_INCLNAME             = sy-repid
           CHANGING
                CT_FIELDCAT            = int_fcat
           EXCEPTIONS
                INCONSISTENT_INTERFACE = 1
                PROGRAM_ERROR          = 2
                OTHERS                 = 3.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                I_CALLBACK_PROGRAM       = i_repid
                I_STRUCTURE_NAME         = 'marav'
                I_DEFAULT                = 'X'
                I_SAVE                   = 'A'
           TABLES
                T_OUTTAB                 = imat.
      IF SY-SUBRC <> 0.
        WRITE: 'SY-SUBRC: ', SY-SUBRC .
      ENDIF.
    Hope this will help.
    Regards,
    Naveen.

  • File Count with selected date range

    Hi,
    Our requirement is to get the file count with selected date by the user from two sharepoint date time controls i.e. dtp1 and dtp2 into the data table. I am able to get the file count of specific folder from Pages library through below code. Now need to get
    the selected date range from two date time picker controls and check with the item created by is within the date range. If yes I need to get the file count.
    So please share your ideas/thoughts to do the same.
    SPList list =
    wikiweb.Lists["Pages"];
                        SPFolderCollection oFolders
    = list.RootFolder.SubFolders["foldername"].SubFolders;
                        DataTable dt
    = new DataTable();
                        dt.Columns.Add("Column1");
                        DataRow dr;
                        if (oFolders.Count
    > 0)
                            foreach (SPFolder oFolder in oFolders)
     if (!oFolder.Name.Equals("Forms"))
                                    dr
    = dt.NewRow(); 
    dr["Column1"] = oFolder.ItemCount.ToString();
    dt.Rows.Add(dr);
    Regards,
    Sudheer
    Thanks & Regards, Sudheer

    Hi,
    I have modified the code as below
    if((DateTime)(oFolder.Item.File.TimeCreated>dtFromDate.SelectedDate)&&(DateTime)(oFolder.Item.File.TimeCreated<dtToDate.SelectedDate))
    But still it is throwing the error.
    Please share your ideas on the same.
    Regards,
    Sudheer
    Thanks & Regards, Sudheer

  • XML/XPath question--how to select a range of elements with XPath?

    Hi there,
    I have an XML DOM in memory. I need to do hold it and issue only parts of it to my client app in "pages". Each page would be a self-contained XML doc, but would be a subset of the original doc. So for instance the first page is top-level elements 1-5. 2nd page would be 6-10 etc. Is this solution best solved with XPath? If not, what's the best way? If so, I have the following question:
    Is there a way to use XPath to select a range of nodes based on position within the document? I know I can do an XPath query that will return a single Node based on position. So for example if I wanted the first node in some XML Book Catalog I could do XPathAPI.selectSingleNode(doc, "/Catalog/Book[position()=1]"); I could wrap the previous call in a loop, replacing the numeric literal each time, but that seems horribly inefficient.
    Any ideas? Thanks much in advance!
    Toby Buckley

    Your question is about marking a range of cells. 99% of the code posted has nothing to do with this. If you want to create a simple table for test purposes then just do:
    JTable table = new JTable(10, 5);
    JScrollPane scrollPane = new JScrollPane( table );
    getContentPane().add( scrollPane );
    In three line of code you have a simple demo program.
    When I leave the mouse button again, these bunch/range of cells shall stay "marked". table.setCellSelectionEnabled( true );
    and I'd like to obtain, say, a vector of a vector containing just those data marked beforeUse the getSelectedRows() and getSelectedColumns() methods for this information. I would suggest you create a Point object to reflect the row/column position and then add the point to an ArrayList.

  • Delete a range of rows in Oracle Table

    How do i delete a range of values in Oracle Table using SQL Pus. For example i have iwanted to delete rows with user_id from 12344 ~ 12399

    ustin thanks for the earlier help. Part of the requiremnt is met, now the tester can delete the rage of rows from 'dropbox', table. I am quiet not done in my second of the requirement. And that is pull the first 100 or 200 etc rows from the parent table (user_auth), and delete them from (dropbox). user_auth does not get affected. I able to user rank and dense_rank by create_time against user_auth table, and get the first 100 or 200 rows. However when join with dropbox, for example dropbox.user_id=user_auth.user_id. Query get hunged. I am not sure do i need to write a procedure for this, or a can be acieved by SQL. This is a test env.
    SQL> desc user_auth
    Name Null? Type
    USER_ID NOT NULL NUMBER(10)
    USER_NAME NOT NULL VARCHAR2(32)
    ACCOUNT_STATUS_CODE NOT NULL NUMBER(3)
    PASSWD VARCHAR2(13)
    DEVICE_ID_TYPE VARCHAR2(10)
    DEVICE_ID VARCHAR2(36)
    OLD_MSISDN NUMBER(15)
    MASTER_LOCK_CODE VARCHAR2(3)
    PARTNER_ID NOT NULL NUMBER(3)
    CREATE_TIME NUMBER(10)
    MAIL_PROVISIONED NOT NULL NUMBER(1)
    PASSWD_TYPE_ID NUMBER(3)
    USER_ID is primary key.
    INDEX_NAME INDEX_TYPE UNIQUENES
    PK_USER_AUTH_USER_ID NORMAL UNIQUE
    I_USER_AUTH_USER_NAME_PARTNER NORMAL UNIQUE
    I_USER_AUTH_DEVICE NORMAL UNIQUE
    I_USER_AUTH_MSISDN NORMAL UNIQUE
    DROPBOX
    Name Null? Type
    USER_ID NOT NULL NUMBER(10)
    DROPBOX_ID NUMBER(10)
    UPDATE_TIME NUMBER(10)
    MESSAGE_TYPE VARCHAR2(64)
    MESSAGE BLOB
    SURVIVE_REBOOT NUMBER(1)
    DELETE_TIME NOT NULL NUMBER(10)
    No Primary KEY
    INDEX_NAME INDEX_TYPE UNIQUENES
    I_DROPBOX_USER_ID NORMAL NONUNIQUE
    I_DROPBOX_SURVIVE_REBOOT NORMAL NONUNIQUE
    If I run
    select user_id, create_time, rnk1 FROM
    (select user_id, user_name, to_char(convert_unix_time(create_time)) create_time, DENSE_RANK() OVER (ORDER BY user_name) rnk1 from user_auth where user_name LIKE '%stomp%_%')
    where rnk1 < 100
    I get the result. How do i select these first 100 rows in the dropbox and delete them. relationship is many to many.

  • Select more than 1 row

    hi!
    I'm looking for a method that can help me taking out of my database the number of rows I want for each page to be displayed...
    ...something like select the first 10 rows,
    than from 11 to 20 and so on...
    ...can somebody help me?

    Here. Remember to fill in the correct username and password and table and column names in the SQL query.
    Hope it helps.
    Mel.
    import java.sql.*;
    public class DatabaseTest
      public static void main(String[] args)
        ResultSet rs = null;
        /** URL of database */
        String URL = "jdbc:mysql://localhost/database_name";
        /** Username used to connect to database */
        String userName = "username";
        /** Password required to connect to database */
        String password = "password";
        /** Database Driver class name */
        String driverName = "org.gjt.mm.mysql.Driver";
        /** SQL Query **/
        String sql = "SELECT * FROM tablename ORDER BY column_name LIMIT 0, 10";
        //Connection
        Connection connection = null;
        boolean isConnected = false;
        //Statement
        Statement statement;
        try
          //Load the driver
          Class.forName(driverName);
          //Connect to the database
          connection = DriverManager.getConnection(URL, userName, password);
          isConnected = true;
        //Catch an error if we couldn't connect
        catch (Exception e)
          System.err.println("Couldn't connect to database. Error: " + e);
          // Kill the connection object
          connection = null;
          isConnected = false;
        try
          //Create a new statement object
          statement = connection.createStatement();
          //Execute the query
          rs = statement.executeQuery(sql);
          if(!rs.next()) System.out.println("No Results found");
           else
             do
               //Print out the results found in the query
               System.out.println("1: " + rs.getString(1));
               System.out.println("2: " + rs.getString(2));
             while(rs.next());
          statement.close();
          connection.close();     
        } //End of try
        catch (Exception e)
          System.err.println(
            "ERROR: Could not connect to database when executing query" + e);
        } //End of catch
    }

  • How does the CBO calculate the selectivity for range predicates on ROWID ?

    Hi all,
    I'm wondering how the CBO estimate the selectivity for range predicates based on ROWID columns.
    For example, for the following query the CBO estimates there's going to be 35004 rows returned instead of 7:
    SQL> SELECT count(*)
      FROM intsfi i
    WHERE
    ROWID>='AAADxyAAWAAHDLIAAB' AND ROWID<='AAADxyAAWAAHDLIAAH';  2    3    4
      COUNT(*)
             7
    Elapsed: 00:00:02.31
    SQL> select * from table(dbms_xplan.display_cursor(null,null,'iostats last'));
    PLAN_TABLE_OUTPUT
    SQL_ID  aqbdu2p2t6w0z, child number 1
    SELECT count(*)   FROM intsfi i  WHERE  ROWID>='AAADxyAAWAAHDLIAAB' AND
    ROWID<='AAADxyAAWAAHDLIAAH'
    Plan hash value: 1610739540
    | Id  | Operation             | Name    | Starts | E-Rows | A-Rows |   A-Time   | Buffers |
    |   0 | SELECT STATEMENT      |         |      1 |        |      1 |00:00:02.31 |   68351 |
    |   1 |  SORT AGGREGATE       |         |      1 |      1 |      1 |00:00:02.31 |   68351 |
    |*  2 |   INDEX FAST FULL SCAN| INTSFI2 |      1 |  35004 |      7 |00:00:02.31 |   68351 |
    Predicate Information (identified by operation id):
       2 - filter((ROWID>='AAADxyAAWAAHDLIAAB' AND ROWID<='AAADxyAAWAAHDLIAAH'))According to Jonathan Lewis' book, for a normal column the selectivity would have been:
    (value_column1-value_column2)/(high_value-low_value)+1/num_distinct+1/num_distinct
    But here with the ROWID column, how does the CBO make its computation ?
    SINGLE TABLE ACCESS PATH
      Single Table Cardinality Estimation for INTSFI[I]
      Table: INTSFI  Alias: I
        Card: Original: 14001681.000000  Rounded: 35004  Computed: 35004.20  Non Adjusted: 35004.20

    Hi Jonathan,
    Some Clarifications
    =============
    DELETE /*+ ROWID(I) */ FROM INTSFI I WHERE
    (I.DAVAL<=TO_DATE('12032008','DDMMYYYY') AND (EXISTS(SELECT 1 FROM
    INTSFI S WHERE S.COINT=I.COINT AND S.NUCPT=I.NUCPT AND S.CTSIT=I.CTSIT
    AND NVL(S.RGCID,-1)=NVL(I.RGCID,-1) AND S.CODEV=I.CODEV AND
    S.COMAR=I.COMAR AND S.DAVAL>I.DAVAL) AND I.COMAR IN (SELECT P.COMAR
    FROM PURMAR P WHERE P.NUPUR=1))) AND ROWID>='AAADxyAAWAAHDLIAAB' AND
    ROWID<='AAADxyAAWAAHDLIAAH'
    Plan hash value: 1677274993
    | Id  | Operation                      | Name    | Starts | E-Rows | A-Rows |   A-Time   | Buffers |  OMem |  1Mem | Used-Mem |
    |   0 | DELETE STATEMENT               |         |      1 |        |      0 |00:00:05.94 |   53247 |    |          |          |
    |   1 |  DELETE                        | INTSFI  |      1 |        |      0 |00:00:05.94 |   53247 |    |          |          |
    |*  2 |   HASH JOIN SEMI               |         |      1 |   9226 |      7 |00:00:05.94 |   53180 |   783K|   783K|  471K (0)|
    |   3 |    NESTED LOOPS                |         |      1 |   9226 |      7 |00:00:00.01 |      10 |    |          |          |
    |*  4 |     TABLE ACCESS BY ROWID RANGE| INTSFI  |      1 |   9226 |      7 |00:00:00.01 |       6 |    |          |          |
    |*  5 |     INDEX UNIQUE SCAN          | PURMAR1 |      7 |      1 |      7 |00:00:00.01 |       4 |    |          |          |
    |   6 |    INDEX FAST FULL SCAN        | INTSFI1 |      1 |     14M|   7543K|00:00:01.73 |   53170 |    |          |          |
    Predicate Information (identified by operation id):
       2 - access("S"."COINT"="I"."COINT" AND "S"."NUCPT"="I"."NUCPT" AND "S"."CTSIT"="I"."CTSIT" AND
                  NVL("S"."RGCID",(-1))=NVL("I"."RGCID",(-1)) AND "S"."CODEV"="I"."CODEV" AND "S"."COMAR"="I"."COMAR")
           filter("S"."DAVAL">"I"."DAVAL")
       4 - access(ROWID>='AAADxyAAWAAHDLIAAB' AND ROWID<='AAADxyAAWAAHDLIAAH')
           filter("I"."DAVAL"<=TO_DATE(' 2008-03-12 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
       5 - access("P"."NUPUR"=1 AND "I"."COMAR"="P"."COMAR")
    When I force the NESTED LOOP SEMI JOIN the query runs faster:
    DELETE /*+ ROWID(I) */ FROM INTSFI I WHERE
    (I.DAVAL<=TO_DATE('12032008','DDMMYYYY') AND (EXISTS(SELECT /*+ NL_SJ
    */ 1 FROM INTSFI S WHERE S.COINT=I.COINT AND S.NUCPT=I.NUCPT AND
    S.CTSIT=I.CTSIT AND NVL(S.RGCID,-1)=NVL(I.RGCID,-1) AND S.CODEV=I.CODEV
    AND S.COMAR=I.COMAR AND S.DAVAL>I.DAVAL) AND I.COMAR IN (SELECT P.COMAR
    FROM PURMAR P WHERE P.NUPUR=1))) AND ROWID>='AAADxyAAWAAHDLIAAB' AND
    ROWID<='AAADxyAAWAAHDLIAAH'
    Plan hash value: 2031485112
    | Id  | Operation                      | Name    | Starts | E-Rows | A-Rows |   A-Time   | Buffers |
    |   0 | DELETE STATEMENT               |         |      1 |        |      0 |00:00:00.01 |      94 |
    |   1 |  DELETE                        | INTSFI  |      1 |        |      0 |00:00:00.01 |      94 |
    |   2 |   NESTED LOOPS SEMI            |         |      1 |   9226 |      7 |00:00:00.01 |      27 |
    |   3 |    NESTED LOOPS                |         |      1 |   9226 |      7 |00:00:00.01 |       9 |
    |*  4 |     TABLE ACCESS BY ROWID RANGE| INTSFI  |      1 |   9226 |      7 |00:00:00.01 |       5 |
    |*  5 |     INDEX UNIQUE SCAN          | PURMAR1 |      7 |      1 |      7 |00:00:00.01 |       4 |
    |*  6 |    INDEX RANGE SCAN            | INTSFI1 |      7 |     14M|      7 |00:00:00.01 |      18 |
    Predicate Information (identified by operation id):
       4 - access(ROWID>='AAADxyAAWAAHDLIAAB' AND ROWID<='AAADxyAAWAAHDLIAAH')
           filter("I"."DAVAL"<=TO_DATE(' 2008-03-12 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
       5 - access("P"."NUPUR"=1 AND "I"."COMAR"="P"."COMAR")
       6 - access("S"."COINT"="I"."COINT" AND "S"."NUCPT"="I"."NUCPT" AND
                  "S"."CTSIT"="I"."CTSIT" AND "S"."CODEV"="I"."CODEV" AND "S"."COMAR"="I"."COMAR" AND
                  "S"."DAVAL">"I"."DAVAL")
           filter(NVL("S"."RGCID",(-1))=NVL("I"."RGCID",(-1)))the above post is from Ahmed AANGOUR
    Case 1 - . If you check Plan hash value: 16772749938
    =====
    TABLE ACCESS BY ROWID RANGE| INTSFI  For every row access from INTSFI - it fetches a record from INDEX UNIQUE SCAN | PURMAR1
    If we check A-rows = 9226
    9226 * 7 = 64582 request across the table - perhaps with hint of rowid it fetches exact rows from PURMAR1
    in this case i think going for hash join with ordered hints (jonathan as you suggest go for leading hint's instead of ordered) - from INTSFI - PURMAR1 - instead of going for IN clause would get the rows that satifies the ("P"."NUPUR"=1 AND "I"."COMAR"="P"."COMAR")
    |*  2 |   HASH JOIN SEMI               |         |      1 |   9226 |      7 |00:00:05.94 |   53180 |   783K|   783K|  471K (0)|
    |   3 |    NESTED LOOPS                |         |      1 |   9226 |      7 |00:00:00.01 |      10 |    |          |          |
    |*  4 |     TABLE ACCESS BY ROWID RANGE| INTSFI  |      1 |   9226 |      7 |00:00:00.01 |       6 |    |          |          |
    |*  5 |     INDEX UNIQUE SCAN          | PURMAR1 |      7 |      1 |      7 |00:00:00.01 |       4 |    |          |          |My understanding with above plan would change to
    HASH JOIN
    TABLE ACCESS BY ROWID RANGE| INTSFI
    INDEX UNIQUE SCAN | PURMAR1
    HASH JOIN
    INDEX FAST FULL SCAN | INTSFI1
    Which migt be feasible.
    2 .
    DELETE /*+ ROWID(I) */ FROM INTSFI I WHERE
    (I.DAVAL<=TO_DATE('12032008','DDMMYYYY') AND (EXISTS(SELECT /*+ NL_SJ
    */ 1 FROM INTSFI S WHERE S.COINT=I.COINT AND S.NUCPT=I.NUCPT AND
    S.CTSIT=I.CTSIT AND NVL(S.RGCID,-1)=NVL(I.RGCID,-1) AND S.CODEV=I.CODEV
    AND S.COMAR=I.COMAR AND S.DAVAL>I.DAVAL) AND I.COMAR IN (SELECT P.COMAR
    FROM PURMAR P WHERE P.NUPUR=1))) AND ROWID>='AAADxyAAWAAHDLIAAB' AND
    ROWID<='AAADxyAAWAAHDLIAAH'Ahmed AANGOUR, modified the query by /*+ NL_SJ */ hint, Instead of that in to remove the most of the rows as we join the tables using subquery, I still doubt it
    to go push_predicate hints - still doubt it.
    Jonathan your comments are most valuable in the above two cases..
    Looking forward to calrify my understanding with concepts of indexes for above test cases
    - Pavan Kumar N

Maybe you are looking for

  • Follow up question. importing audio

    Hello, thanks to all that responded to my question about importing audio from itunes to FCP5. I finally got it onto my timeline, but before I did that I burned it to a cd, and used that to import it to FCP. Probably more steps than necessary, but I f

  • Numbers '09 2.1 - setting import delimiter for .txt or .rtf

    Hi there - I have a series of text files with leading numbers that I'd like to remove. The files are lists, where each line is enumerated sequentially & these line-numbers have to be removed for further processing. This is too painful to do manually

  • Excise Duty rate change in J1iex

    Hi, I am maintaining exceptional duty rate in J1id. While posting the j1iex, the rate is only taking from the Purchase Order and not from J1id. How to solve this.? . Every time we are changing the PO FV 11 conditions and posting J1iex.Please help Reg

  • Having Some Mail issues on Apple Mail 5.2

    Hi All - Having some mail issues lately with my gmail account Imap set up. I can receive mail but when trying to send mail it pops up with the follwoing: "Can not send message using the server smtp.gmail.com" I tried deleting the gmail account on my

  • BP Permission

    Dear All, I created a BP from Submittals and made changes in forms, Items Logs and everything, I granted permission for myself for all actions. I validated the process and no errors found then deployed the process I setup the process in my project an