Spit the count into rows in 10 division format

Hi Gurus,
I want to create a function in which i pass any number it gives rows in division of 10 .
Example: if i pass a count 34
then it should split like
10
10
10
3
If i pass 24
10
10
4
Can you please help me out ?
Thanks in advance! Appreciated.

OracleExplorer wrote:
OR
with t as (select 43 cnt  from dual)
SELECT case when a * 10 > cnt then cnt +10 - a*10 else 10 end  split_data  FROM t, xmltable('(1 to xs:int($n) )' passing  ceil(t.cnt/10) AS "n" columns a FOR ordinality);
isn't using XML functionality a little bit over the top for this requirement?
How about just...
SQL> ed
Wrote file afiedt.buf
  1  with t as (select 34 as cnt from dual)
  2  --
  3  -- end of test data
  4  --
  5  select case when rownum*10 < cnt then 10 else mod(cnt,10) end as cnt
  6  from t
  7* connect by rownum <= ceil(cnt/10)
SQL> /
       CNT
        10
        10
        10
         4
SQL>Or some confusing maths...
SQL> ed
Wrote file afiedt.buf
  1  with t as (select 34 as cnt from dual)
  2  --
  3  -- end of test data
  4  --
  5  select sign(floor((cnt/10)-rownum)+1)*10+(mod(cnt,10)*power(sign(floor((cnt/10)-rownum)+1)-1,2)) as cnt
  6  from t
  7* connect by rownum <= ceil(cnt/10)
SQL> /
       CNT
        10
        10
        10
         4;)

Similar Messages

  • Best way to find the count of rows affected by a query

    Hi All,
    Is there a way to find the row count without actually executing the SQL statement? The count need not be accurate but it should be within acceptable limits. I know we can use 'explain plan' for this. But the value in plan_table.cardinality is way out of the actual expected count.
    We would appreciate any pointers and/or suggestions.
    Thanks
    Edited by: user779842 on May 4, 2011 2:21 AM

    maybe you can try this
    How to get estimated number of rows of query without running actual query :
    CREATE OR REPLACE FUNCTION get_rows_number (sql_select VARCHAR2, sql_id VARCHAR2) RETURN NUMBER AS
    rows_number NUMBER;
    BEGIN
    EXECUTE IMMEDIATE
    ‘EXPLAIN PLAN SET STATEMENT_ID = ‘||CHR(39) || sql_id || CHR(39)||’ FOR ‘ || sql_select;
    SELECT t.cardinality
    INTO rows_number
    FROM plan_table T
    WHERE statement_id = sql_id AND ID = 0;
    RETURN rows_number;
    END;hope it helps!

  • Getting the count of rows present in the oracle table

    Hi all,
    i want to get the total number of rows present in the sql table to the appmodule.
    After applying the some view criteria to the view object. if it try with getallrowsinrange it was giving count of rows present in the viewobject but i want total number of rows present in the sql table.
    How can i get that
    I am using jdev 11.1.1.5
    Thanks in advance

    I threw something together, quick and dirty, feel free to optimize.
    Assuming that you want the table count, I put the code into a EntityDefImpl subclass since this is what represents a table in the middle-tier.
    public class EmpDefImpl
          extends EntityDefImpl {
       * This is the default constructor (do not remove).
      public EmpDefImpl( ) {}
      //~ Methods ****************************************************************************
      public long getTableRowCount( DBTransaction transaction ) {
        String query = getQuery( );
        String countQuery = String.format( "SELECT COUNT(*) FROM (%s)", query );
        long count = 0;
        ViewObject vo = transaction.createViewObjectFromQueryStmt( countQuery );
        try {
          vo.executeQuery( );
          Row row = vo.first( );
          Number number = (Number)row.getAttribute( 0 );
          count = number.longValue( );
        } finally {
          vo.remove( );
        return count;
    }Depending on your type map, you might not get a oracle.jbo.domain.Number, but something else, so the cast might need correction.
    Usage example:
    public class EmpEditViewImpl extends ViewObjectImpl {
      public EmpEditViewImpl() {
      protected void executeQueryForCollection( Object object, Object[] object2, int i ) {
        super.executeQueryForCollection( object, object2, i );
        EmpDefImpl def = ( EmpDefImpl )getEntityDef( 0 );
        long tableRowCount = def.getTableRowCount( getDBTransaction() ) );
        // Do something with it
    }As you can see, the code is pretty generic. You might also be able to put this into an ADF extension base class.
    Sascha
    Edited by: Sascha Herrmann on Jun 7, 2012 2:39 PM

  • Get the count of rows in a table control

    Hi Experts,
      How do I get the count of the rows in a table control during run time.
    I am developing a BDC in which I have to check all entries in a table control.
    My requirement is to get the total number of rows in a table control dynamically.
    Thanks
    Kumar

    Hi,
    Use a variable when u r passing the records from the internal table to the screen fields
    and display the same.
    I think this idea may help u.
    And pls explain me ur requirement clearly.
    Refer to the following link this may help u.
    http://sapabapnotes.blogspot.com/2008/03/working-with-ecatt-extended-computer.html
    Reward if helpful.
    Jagadish

  • Can query output the result into excel with a fix format?

    Hi Expert,
    My user giving me a requirement for new reports. They do not want the standard SAP report format but they want the result to be populate into a excel template with their own fix format. Can BW generate the report like this? Or it is out of the functionality of BW. FYI, I'm using SAP BI 7.0.
    Thanks!
    Regards.

    Hi Ang,
    You have a way to do through the Bex Analyzer.
    Please get the excel template in that please use a analysis design item in the place of the query result display.
    Then after adding the analysis item then please assign a DP (data provider) with the query you have created.
    After that please save the work book in your roles or fav's.
    Note: some important settings has to be changed for the workbook.
    In workbook settings, tick mark the property "REFRESH upon open of work book"
    With Regards,
    Ravi

  • Count of rows in ALv report

    Hi!
    I would like to get the count of rows in my ALV report . How to get the count of the rows ? Can anyone guide me in getting it dome please.
    Thanks

    Hi Gaddemmedi!
    I am attaching the report as you had asked for. I have added the things you asked me to do and now I am getting the count on the top of the page. The problem is that though it shows me the count of the lines from the LAV report on top but when I try to filter the records in the report that count first of all dosent change and remain the same as the initial number of record though after filtering records reduce and over that the count lines keep on increasing I mean the count is shown in repeated lines afet lines. Kindly help please.
    Thanks
    *& Report  ZSD_BILLING_HDR_TEXT_sum                                       *
    *&         billing doc. and associated header text report              *
    *&                            CHANGE LOG                               *
    *& jpoon 2007.08.03                  Change request: DEVK905095        *
    *& Move request: SD_1451_01          Requestor: Mona Fox               *
    *& FP14134 - original code.                                            *
    REPORT  zsd_billing_hdr_text_sum MESSAGE-ID zsd NO STANDARD PAGE HEADING.
    * For ALV usage
    TYPE-POOLS: slis.
    DATA: gs_layout   TYPE slis_layout_alv,
          tp_print    TYPE slis_print_alv,
          gt_sort     TYPE slis_t_sortinfo_alv,
          gt_events   TYPE slis_t_event,
          t_fieldcat  TYPE slis_t_fieldcat_alv WITH HEADER LINE,
          repid       TYPE syrepid,               " ABAP Program.
          gt_list_top_of_page TYPE slis_t_listheader,     " Top of page text.
          alv_variant   TYPE disvariant," Customize Disp. Variant
          w_event type slis_alv_event.
    DATA: w_field    TYPE slis_fieldcat_alv.
    TABLES: vbrk, vbrp, vbpa.
    DATA  SLIS_EV_AFTER_OUTPUT.
    data: gs_list_top_of_page type slis_listheader.
    *data: gt_list_top_of_page type slis_t_listheader.
    * Definition of selection screen                                       *
    *   By plant, storage location, sold-to customers, material and        *
    *   posting date of the sales orders                                   *
    SELECTION-SCREEN BEGIN OF BLOCK one WITH FRAME TITLE text-001.
    SELECT-OPTIONS: s_vbeln  FOR  vbrk-vbeln,      " billing doc.
                    s_kunnr  FOR  vbpa-kunnr,      " bill-to customer number.
                    s_werks  FOR  vbrp-werks,      " line item plant.
                    s_fkdat  FOR  vbrk-fkdat,      " billing date.
                    s_fkart  FOR  vbrk-fkart,      " billing type.
                    s_vkorg  FOR  vbrk-vkorg.      " sales org.
    PARAMETERS:     p_hold   AS CHECKBOX.
    SELECTION-SCREEN END OF BLOCK one.
    * ALV display layout
    SELECTION-SCREEN BEGIN OF BLOCK layout WITH FRAME TITLE text-003.
    PARAMETERS: pa_vari TYPE slis_vari DEFAULT ' '. " Display variant.
    SELECTION-SCREEN END OF BLOCK layout.
    * Data Definitions                                                     *
    * Storing Extracted Info.
    TYPES: BEGIN OF t_extract,
             vbeln        TYPE vbeln_vf,   " Sales order number.
             posnr        TYPE posnr,      " line item
             fkart        TYPE fkart,      " billing type.
             vtext        TYPE BEZEI20,    " billing type description.
             fkdat        TYPE fkdat,      " billing date.
             werks        TYPE werks_d,    " line item plant.
             werks_name1  TYPE name1,      " plant description.
             kunnr        TYPE kunnr,      " bill-to customer.
             kunnr_name1  TYPE name1_gp,   " bill-to description.
             netwr        TYPE netwr,      " net value,invoice total $
             zzflag       TYPE boolean,    " hold indicator
             zzreason     TYPE char30,     " header text2 (reason)
             zzuser       TYPE ernam,      " last changed by
             zz_changed_date TYPE dats,    " last changed date
             zz_changed_time TYPE tims,    " last changed time
            END OF t_extract.
    DATA: it_extract  TYPE TABLE OF t_extract WITH HEADER LINE,
          it_extract2 TYPE TABLE OF t_extract WITH HEADER LINE.
    DATA: it_text TYPE TABLE OF tline WITH HEADER LINE.
    DATA: wa_thead type thead.
    DATA: w_tdname type TDOBNAME.
    DATA: L_COUNT TYPE I.
    * initialization
    INITIALIZATION.
      gs_layout-colwidth_optimize = 'X'.
      tp_print-no_print_listinfos = 'X'.
      tp_print-no_coverpage = 'X'.
      PERFORM set_fieldcat.
      PERFORM alv_eventtab_build USING:
    **    Event name     Form to execute     Event internal table
       'TOP_OF_PAGE'  'TOP_OF_PAGE'       gt_events[].
    * Dropdown list for all created ALV layouts, global or user-specific
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR pa_vari.
      PERFORM alv_variant_f4 CHANGING pa_vari.
    * Main BODY of processing logic
    START-OF-SELECTION.
      IF s_vbeln IS INITIAL
      AND s_kunnr IS INITIAL
      AND s_werks IS INITIAL
      AND s_fkdat IS INITIAL
      AND s_fkart IS INITIAL
      AND s_vkorg IS INITIAL.
         MESSAGE i000 WITH text-037 ' ' ' ' ' '.
      ELSE.
        PERFORM extract_data.
      ENDIF.
    END-OF-SELECTION.
      IF it_extract2[] IS INITIAL.
        MESSAGE i000 WITH text-002 ' ' ' ' ' '.
      ELSE.
    * Build headings for report.
    *    PERFORM build_top_of_page  USING gt_list_top_of_page[].
    * describe table it_extract2 lines l_count.
    *write :/ 'TOTAL NO OF ENTRIES', SY-VLINE, 32 L_COUNT.
          PERFORM call_alv.
    *write :/ 'TOTAL NO OF ENTRIES', SY-VLINE, 32 L_COUNT.
      ENDIF.
    *&      Form  EXTRACT_KEY_DATA
    * Retreive the data for the report.
    FORM extract_data.
      CLEAR: it_extract.  REFRESH: it_extract.
    * read and select billing documents
      IF p_hold IS INITIAL.
        SELECT vbrk~vbeln vbrk~fkart vbrk~fkdat vbrk~netwr
               vbrk~zzflag vbrk~zzreason vbrk~zzuser
               vbrk~zz_changed_date vbrk~zz_changed_time
               vbrp~posnr vbrp~werks
          INTO CORRESPONDING FIELDS OF TABLE it_extract
          FROM vbrk INNER JOIN vbrp ON
               vbrk~vbeln = vbrp~vbeln
         WHERE vbrk~vbeln IN s_vbeln
           AND vbrk~fkart IN s_fkart
           AND vbrk~fkdat IN s_fkdat
           AND vbrk~vkorg IN s_vkorg
           AND vbrk~fksto NE 'X'
           AND vbrp~werks IN s_werks.
      ELSE.
    * read 'held' documents only as per selection
        SELECT vbrk~vbeln vbrk~fkart vbrk~fkdat vbrk~netwr
               vbrk~zzflag vbrk~zzreason vbrk~zzuser
               vbrk~zz_changed_date vbrk~zz_changed_time
               vbrp~posnr vbrp~werks
          INTO CORRESPONDING FIELDS OF TABLE it_extract
          FROM vbrk INNER JOIN vbrp ON
               vbrk~vbeln = vbrp~vbeln
         WHERE vbrk~vbeln IN s_vbeln
           AND vbrk~fkart IN s_fkart
           AND vbrk~fkdat IN s_fkdat
           AND vbrk~vkorg IN s_vkorg
           AND vbrk~fksto NE 'X'
           AND vbrk~zzflag = 'X'
           AND vbrp~werks IN s_werks.
      ENDIF.
      IF sy-subrc <> 0.
        MESSAGE i000 WITH text-002 ' ' ' ' ' '.
      ENDIF.
      CHECK sy-subrc = 0.
    * only need first line item for this report.
      SORT it_extract BY vbeln posnr.
      DELETE ADJACENT DUPLICATES FROM it_extract COMPARING vbeln.
      LOOP AT it_extract.
    * Retrieve and select by sales order bill-to on header level
    * as well as lookup bill-to customer name/description
        SELECT SINGLE kunnr FROM vbpa INTO it_extract-kunnr
         WHERE vbeln = it_extract-vbeln
           AND posnr = '000000'
           AND parvw = 'RE'.
        IF it_extract-kunnr IN s_kunnr.
          it_extract-kunnr_name1 = zcl_kna1=>get_name1( it_extract-kunnr ).
        ELSE.
          DELETE it_extract.
          CONTINUE.
        ENDIF.
    * lookup billing type description
        SELECT SINGLE vtext FROM tvfkt
          INTO it_extract-vtext
         WHERE spras = sy-langu
           AND fkart = it_extract-fkart.
        IF sy-subrc <> 0.
          clear it_extract-vtext.
        ENDIF.
    * lookup plant description
        SELECT SINGLE name1 FROM t001w
          INTO it_extract-werks_name1
         WHERE werks = it_extract-werks.
        IF sy-subrc <> 0.
          clear it_extract-werks_name1.
        ENDIF.
        MOVE-CORRESPONDING it_extract TO it_extract2.
        APPEND it_extract2.
       ENDLOOP.
    describe table it_extract2 lines l_count.
    ENDFORM.                    " EXTRACT_DATA
    *&      Form  SET_FIELDCAT
    * Create the field catalogue.
    FORM set_fieldcat .
    *CLEAR W_EVENT.
    *W_EVENT-FORM = SLIS_EV_AFTER_OUTPUT.
    *W_EVENT-NAME = SLIS_EV_AFTER_LINE_OUTPUT.
    *APPEND W_EVENT TO GT_EVENTS.
      CLEAR w_field.
      CLEAR t_fieldcat.  REFRESH t_fieldcat.
      w_field-col_pos = 1.
      w_field-fieldname = 'ZZFLAG'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Hold Printing'(005).
      APPEND w_field TO t_fieldcat.
      w_field-col_pos = 2.
      w_field-fieldname = 'ZZREASON'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Reason'(036).
      APPEND w_field TO t_fieldcat.
      w_field-col_pos = 3 .
      w_field-fieldname = 'VBELN'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Billing Doc'(028).
      w_field-emphasize = 'X'.
      w_field-hotspot   = 'X'.
      APPEND w_field TO t_fieldcat.
      CLEAR w_field.
      w_field-col_pos = 4 .
      w_field-fieldname = 'VTEXT'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Type Description'(030).
      APPEND w_field TO t_fieldcat.
      w_field-col_pos = 5 .
      w_field-fieldname = 'FKDAT'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Billing Date'(031).
      APPEND w_field TO t_fieldcat.
      w_field-col_pos = 6 .
      w_field-fieldname = 'WERKS'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Plant'(012).
      APPEND w_field TO t_fieldcat.
      w_field-col_pos = 7 .
      w_field-fieldname = 'WERKS_NAME1'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Plant Description'(032).
      APPEND w_field TO t_fieldcat.
      w_field-col_pos = 8.
      w_field-fieldname = 'KUNNR'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Bill-to Customer'(033).
      APPEND w_field TO t_fieldcat.
      w_field-col_pos = 9 .
      w_field-fieldname = 'KUNNR_NAME1'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Bill-to Description'(034).
      w_field-emphasize = 'X'.
      w_field-hotspot   = 'X'.
      APPEND w_field TO t_fieldcat.
      CLEAR w_field.
      w_field-col_pos = 10 .
      w_field-fieldname = 'NETWR'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Invoice Amount'(035).
      APPEND w_field TO t_fieldcat.
      w_field-col_pos = 11 .
      w_field-fieldname = 'ZZUSER'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Changed By'.
      APPEND w_field TO t_fieldcat.
      w_field-col_pos = 12 .
      w_field-fieldname = 'ZZ_CHANGED_DATE'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Last Changed Date'(006).
      APPEND w_field TO t_fieldcat.
      w_field-col_pos = 13 .
      w_field-fieldname = 'ZZ_CHANGED_TIME'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Last Changed Time'(007).
      APPEND w_field TO t_fieldcat.
    *  W_event-NAME = slis_ev_end_of_list.
    *  W_event-FORM = 'END_OF_LIST'.
    *  APPEND W_event  TO GT_EVENTS.
    *  CLEAR W_event .
    *  w_field-col_pos = 14 .
    *  w_field-fieldname = 'COUNT'.
    *  w_field-tabname = 'IT_EXTRACT2'.
    *  w_field-seltext_l = 'COUNT'.
    *  APPEND w_field TO t_fieldcat.
    ENDFORM.                    " SET_FIELDCAT
    *&      Form  CALL_ALV
    * Call the ALV Grid function.
    FORM call_alv .
      SORT it_extract BY vbeln.
    * repid is necessary since the ALV F.M. does not work properly with
    * sy-repid.
      repid = sy-repid.
      alv_variant-variant  = pa_vari.
      alv_variant-report   = sy-repid.
      alv_variant-username = sy-uname.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program      = repid
          i_callback_user_command = 'USER_COMMAND'
          is_layout               = gs_layout
          it_fieldcat             = t_fieldcat[]
          it_sort                 = gt_sort[]
          i_default               = 'X'
          i_save                  = 'A'
          is_variant              = alv_variant
          it_events               = gt_events[]
          is_print                = tp_print
        TABLES
          t_outtab                = it_extract2
        EXCEPTIONS
          program_error           = 1
          OTHERS                  = 2.
    write :/ 'TOTAL NO OF ENTRIES', SY-VLINE, 32 L_COUNT.
      IF sy-subrc NE 0.
        MESSAGE w000 WITH text-004 ' ' ' ' ' '.
      ENDIF.
    ENDFORM.                    " CALL_ALV
    *&      Form  alv_eventtab_build
    *     Pass list of events to be triggered by the ALV function module
    FORM alv_eventtab_build USING  u_name  TYPE slis_alv_event-name
                                   u_form  TYPE slis_alv_event-form
                                   alv_lt_events  TYPE slis_t_event.
      DATA: ls_event TYPE slis_alv_event.   " structure for event handling
      ls_event-name = u_name.
      ls_event-form = u_form.
      APPEND ls_event TO alv_lt_events.
    ENDFORM.                    " alv_eventtab_build
    *       FORM TOP_OF_PAGE                                              *
    FORM top_of_page.
    *gs_list_top_of_page-type = 'H'.
    GS_LIST_TOP_OF_PAGE-INFO = L_COUNT.
    APPEND GS_LIST_TOP_OF_PAGE TO GT_LIST_TOP_OF_PAGE.
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          i_logo             = 'NEWALTA_LOGO'
          it_list_commentary = gt_list_top_of_page.
    ENDFORM.                    " TOP_OF_PAGE
    *&      Form  user_command
    * Process the user command.
    *      -->R_UCOMM      User command
    *      -->RS_SELFIELD  Field selected
    FORM user_command USING r_ucomm     LIKE sy-ucomm
                            rs_selfield TYPE slis_selfield.
      DATA: ltp_vbeln TYPE vbeln.  " Sales document number.
      CASE  r_ucomm.
        WHEN '&IC1'.
          IF ( rs_selfield-fieldname = 'VBELN'
            OR rs_selfield-fieldname = 'BILL_VBELN' )
           AND rs_selfield-value IS NOT INITIAL.        " Display sales document.
            ltp_vbeln = rs_selfield-value.
            zcl_sales_doc=>display( ltp_vbeln ).
          ENDIF.
      ENDCASE.
    ENDFORM.                    "user_command
    *&      Form  alv_v-ariant_f4
    * Get the display variant.
    *      <--CTP_VARI  Variant name
    FORM alv_variant_f4 CHANGING ctp_vari TYPE slis_vari.
      alv_variant-report   = sy-repid.             " Report ID
      alv_variant-username = sy-uname.             " User ID
      CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
        EXPORTING
          is_variant = alv_variant
          i_save     = 'A'
        IMPORTING
          es_variant = alv_variant
        EXCEPTIONS
          OTHERS     = 1.
      IF sy-subrc = 0.
        ctp_vari = alv_variant-variant.
      ENDIF.
    ENDFORM.                    " alv_variant_f4

  • Need Query to that generate count of rows of all tables

    Hi
    i need a query which gives the result of no.of rows in talbe and coresponding table name.
    And then i need to compare the same with other DB schema
    Thanks in advance

    Hi User,
    We can also get the count of rows for all the tables associated with a User, we can create a custom function which
    uses the table name to return results.
      CREATE OR REPLACE FUNCTION TAB_ROWS_CNT (TAB_NAME IN VARCHAR2)
       RETURN NUMBER
    AS
       TAB_CNT   NUMBER :=0;
    BEGIN
       EXECUTE IMMEDIATE 'select count(*) from ' || TAB_NAME
          INTO TAB_CNT;
       RETURN TAB_CNT;
    END;And query,
    SELECT TABLE_NAME, TAB_ROWS_CNT (TABLE_NAME) ROW_CNT
      FROM USER_TABLES;Which gets us the count of Individual Tables for a user.
    This is an just that we can do in this way also. But, use which is optimal.
    Thanks,
    Shankar

  • Paging and count of rows

    Hi,
    I have a procedure doing paging and returning the count of rows:
    As you see I used 2 select, one for paging and one for getting total row counts.
    Is there a way to get rid of "SELECT count(*) into PO_TOTAL FROM TABLE1;"?
    CREATE OR REPLACE PACKAGE BODY MYPACKAGE AS
    TYPE T_CURSOR IS REF CURSOR;
    PROCEDURE SP_PAGING
    PI_STARTID IN NUMBER,
    PI_ENDID IN NUMBER,
    PO_TOTAL OUT NUMBER,
    CUR_OUT OUT T_CURSOR
    IS
    BEGIN
    OPEN CUR_OUT FOR
    SELECT *
    FROM (SELECT row_.*, ROWNUM rownum_
    FROM (
    SELECT column1, column2, column3 FROM TABLE1
    ) row_
    WHERE ROWNUM <= PI_ENDID)
    WHERE rownum_ >= PI_STARTID;
    SELECT count(*) into PO_TOTAL FROM TABLE1;
    END SP_PAGING;
    END MYPACKAGE;

    Yes, I can reproduce that:
    SQL> create table emp1 as select * from emp
      2  /
    Table created.
    SQL> exec dbms_stats.gather_table_stats('SCOTT','EMP1');
    PL/SQL procedure successfully completed.
    SQL> EXPLAIN PLAN FOR
      2  SELECT  ename,
      3          job,
      4          sal,
      5          cnt
      6    FROM  (
      7           SELECT  ename,
      8                   job,
      9                   sal,
    10                   count(*) over() cnt,
    11                   row_number() over(order by 1) rn
    12             FROM  emp1
    13          )
    14    WHERE rn BETWEEN 4 AND 9;
    Explained.
    SQL> @?\rdbms\admin\utlxpls
    PLAN_TABLE_OUTPUT
    Plan hash value: 1444408506
    | Id  | Operation           | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT    |      |    14 |   728 |     4  (25)| 00:00:01 |
    |*  1 |  VIEW               |      |    14 |   728 |     4  (25)| 00:00:01 |
    |   2 |   WINDOW BUFFER     |      |    14 |   252 |     4  (25)| 00:00:01 |
    |   3 |    TABLE ACCESS FULL| EMP1 |    14 |   252 |     3   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
       1 - filter("RN">=4 AND "RN"<=9)
    15 rows selected.
    SQL> EXPLAIN PLAN FOR
      2  SELECT *
      3  FROM (SELECT row_.*, ROWNUM rownum_
      4  FROM (
      5  SELECT ename,job,sal, count(*) over() FROM emp1
      6  ) row_
      7  WHERE ROWNUM <= 9)
      8  WHERE rownum_ >= 4;
    Explained.
    SQL> @?\rdbms\admin\utlxpls
    PLAN_TABLE_OUTPUT
    Plan hash value: 519025698
    | Id  | Operation             | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT      |      |     9 |   468 |     2   (0)| 00:00:01 |
    |*  1 |  VIEW                 |      |     9 |   468 |     2   (0)| 00:00:01 |
    |*  2 |   COUNT STOPKEY       |      |       |       |            |          |
    |   3 |    VIEW               |      |     9 |   351 |     2   (0)| 00:00:01 |
    |   4 |     WINDOW BUFFER     |      |     9 |   162 |     2   (0)| 00:00:01 |
    |   5 |      TABLE ACCESS FULL| EMP1 |     9 |   162 |     2   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
       1 - filter("ROWNUM_">=4)
       2 - filter(ROWNUM<=9)
    18 rows selected.
    SQL> However, you interpreted it incorrectly. Your query will still fetch all rows in TABLE1. Optimizer is smart enough to stop creating window buffer after 9 rows and that is what you see 9 in explain plan, while my query builds 14 row window buffer and then filters. So your query will be a bit faster.
    SY.
    Edited by: Solomon Yakobson on Jan 25, 2009 2:51 PM

  • Need to know how to limit the number of rows returned on Oracle

    MS SQL Server has a command called 'set row count'.
    We are trying to find similar one on Oracle.
    What we are trying to do is that instead of using rownum in the query statement, we would like to find way to limit the number of rows returned. I understand that we can use JDBC resultSet object, but that's not what we want.
    I know Oracle has one called arraysize, but this would not limit the number of rows returned either.
    Pease help.
    Thanks

    I understand that we can use JDBC resultSet object, but that's not what we want.I'm not sure which feature of ResultSet you use and which not.
    But if this question has anything to do with JDBC (that's the forum where you put it), I'd recommend to use Statement.setMaxRows(). This will limit the count of rows which your statement will fetch into it's ResultSet.

  • Count of rows from different tables.

    Hi Friends,
    I have 4 tables with a common column name "ID". I would like to get the count of rows from all the four tables which has the same ID.
    Ex
    select count(a.id) from table1 a,table2 b,table3 c,table4 d where a.id=b.id=c.id=d.id=5;
    please suggest me some solution

    may be thsi?
    select count(a.id) from table1 a,table2 b,table3 c,table4 d
    where a.id=b.id and a.id=c.id and a.id=d.id and a.id=5;

  • Count of rows of a table in header

    Hi Experts,
    I am stuck in a tricky scenario.
    I need to get the count of rows of a table in a webi report in the header of the report.
    And the count should change dynamically according to the filtering done on the table.
    For eg.
    If I have 10 countries in a table, so table has 10 rows.
    Now the count on header should show 10.
    Now if we filter the column to 5 countries, the count on the header should change to 5.
    Any Idea's.
    Regards,
    Gaurav

    Nops
    It doesn't work.
    Let me reframe my issue again:
    I dragged country object on my report.
    UK
    US
    JAPAN
    CANADA
    Now lets say in the report title, I write the formula as =Count(country)
    It will give me 4.
    Now I clicked on the column country and applied filter i.e. country = US ; UK
    Now the block shows
    UK
    US
    In the header the cell still shows 4, which I want to see as 2.
    Any ideas....?
    Thanks
    Gaurav

  • Getting the no. of rows returned from the resultset

    Could somebody tell how can I get the count of rows from the resultset object.
    Thanks a lot in advance

    hmmm 20,710 topics and 69,000 odd posts and no one has EVER asked this question before.. it's a miracle....
    or maybe it has been asked and dealt with approx... 11,000 times.
    here is a discussion from 1998 for example http://forum.java.sun.com/thread.jsp?forum=48&thread=83958

  • ABAP WD:  Count of rows using display_type_hierarchy in ALV

    Hi,
    I am trying to implement display_type_hierarchy in ALV and my requirement is to change the hierarchy based on user selection.
    I am able to get the hierarchy based on user selection. For ex: If there are 3 columns in ALV then user can choose the column in a dropdown box and see the hierarchy based on the chosen column. But I want to get the count of rows inside the hierarchy. I did not find any standard method for this. (Is there one?) Could you please let me know how to do it?
    Regards,
    Srini.

    G'day Anett,
    Did you manage to get an answer to this issue, we are trying to do the same thing.
    Cheers,
    Mick.

  • Sqlldr; restrict count of rows

    How can I restrict the count of rows to load.
    The skip option allows to skip the first rows, but how can I stop if a defined count of rows is loaded?
    I need that for testing
    Thanks for your help.
    Frank

    I have to use to original data in my test case and can not modify the input file.
    I like to restrict the count of loaded rows in the control file.

  • Get the Count for each row

    I'm trying to get the count for each row to total count for each month
    Something like this
    Hardware     |      Jan
    Monitors       |       5
    Processors   |      137
    Printers        |      57
    etc........
    How can I write a query for this. I can get the Hardware column but don't know how to get the next column.

    If you can provide more data like sample input DML statements it would have been wonderful..
    Assuming is , you need a pivot. Here is an article on basic Pivot..
    http://sqlsaga.com/sql-server/how-to-use-pivot-to-transform-rows-into-columns-in-sql-server/
    something like this may be..
    DECLARE @Input TABLE
    Hardware VARCHAR(20),
    [Date] VARCHAR(20)
    INSERT INTO @Input VALUES('Monitor', '01/01/2014'), ('CPU', '01/01/2014'), ('Monitor', '01/03/2014')
    , ('ABC', '01/01/2014'),('Monitor', '02/01/2014')
    ;WITH CTE AS
    SELECT Hardware, LEFT(DATENAME(M, [Date]),3) AS [MonthName] FROM @Input
    SELECT *
    FROM
    SELECT Hardware, [MonthName], COUNT(Hardware) AS Count FROM CTE GROUP BY Hardware, [MonthName]) a
    PIVOT (MAX([Count]) FOR [MonthName] IN ([Jan], [Feb])) pvt
    Please mark as answer, if this has helped you solve the issue.
    Good Luck :) .. visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles.

Maybe you are looking for