Help - > Partition by report SQL

Our users have a problem with the formula on the reports below. I don't know what that means. Our users have said that they need

(Tons used (s) / spread miles) * 2000 lb/ton = thousand lbs/spread for their report.

And I see below the formula used by our developer. Don't know how to make for good reading. Can you let me know the formula used in the code below could in fact represent the formula above. Users complained as below
user-> column double and triple the amount, if there are multiple records for the same truck/driver/beat/with the same amount for used dry carpet and Miles to spread. If miles of spread or used dry carpet is different if calculated correctly.


Published by: Lucy discover March 28, 2011 13:50

Have you tried my suggestion above?

(i.e. without using the SUM)

Tags: Database

Similar Questions

  • Please, help me to query SQL Construct.


    Hi Experts,

    Could you please help me to query SQL Construct.  Please find the details

    HOSTNAME HOSTTYPE DEM R1 R2
    RS123 P ABC 24.5 265,5

    RS123 P CYC 24.5 265,5

    RS123 P ADDS 24.5 265,5

    RS123 P ADE 24.5 265,5

    RS123 P SRC 24.5 265,5

    EXPECTED RESULTS

    HOSTNAME      HOSTTYPE                              MNE                                                                      R1          R2
    RS123 P ABC, CYC, ADD, ADE, CBC 24.5 265,5

    Concerning

    See you soon

    with t as)

    Select "RS123' hostname 'P' hosttype, 'ABC' dem, 24.5 r1, r2 265,5 Union double all the

    Select 'RS123', 'P', "CYC", 24.5, 265,5 double Union all

    Select 'RS123', 'P', 'ADD', 24.5, 265,5 double Union all

    Select "RS123', 'P', 'ADE', 24.5, 265,5 double Union all

    Select 'RS123', 'P', 'SRC', 24.5, 265,5 double

    )

    Select the host name,

    HostType,

    RTrim (XMLAGG (XmlElement(e,MNE,','). (Extract ('//Text ()')), ',') DEM,.

    R1,

    R2

    t

    Group hostname,

    HostType,

    R1,

    R2

    /

    HOSTN H DEM R1 R2
    ----- - -------------------- ---------- ----------
    RS123 P ABC, CBC, ADE, ADD, CYC 24.5 265,5

    SQL >

    SY.

  • help on editing a SQL

    DELETE FROM my_table t1
        WHERE rowid NOT IN ( SELECT min(rowid) 
                             FROM my_table t2
                             GROUP BY key_value1 );
    I want to delete duplicates of records in MY_TABLE and table itself contains about 45 million documents. KEY_VALUE1 is whole and indexed.

    Can someone help me change this SQL to make it faster and more efficient?

    Appreciated.

    For very large delete operations, it is generally faster to insert values to keep in another table. Then truncate the original table and rename or reinsert the maintained values.

    example not tested

    insert into t1_temp
    select * from my_table t1
    WHERE rowid IN ( SELECT min(rowid)
                             FROM my_table t2
                             GROUP BY key_value1 );
    
    truncate table t1;
    
    insert into t1 select * from t1_temp;
    
    truncate table t1_temp;
    

    Be aware that a truncate command will do an implicit validation. So do not run without good test.

    Published by: Sven w. March 9, 2011 19:21

  • (Updated report) SQL query

    Is it possible to convert an existing SQL query report area to an "application SQL (editable report)? If not, where should we do to create a SQL (editable report) region?

    I had the same problem.

    The way I ended up converting my sql to a (editable report) SQL query was:

    Create a new page with the type of form and tabular presentation, run through all the steps required Wizard.

    Once done, you can go back and modify the report and paste in your original sql code.

    Worked for me.

    It will be useful.

    Jen

    Published by: munsej on August 7, 2009 08:42

  • I need help on creating reports on the intranet.

    I need help on creating reports on the intranet.
    My level: Beginner cf.
    Y at - it a book for report design? And structures for reports?
    ------------------------------------------------requirements
    my form needs one

    · Date of the box you want. (from and to).
    · Option button to choose the csv and html
    · Run and throw out the results in a tabular format. (grids, cell)


    How many cfm pages do need me for this? E.g. display, action.
    What called what?
    What else do I need?

    I suggest that you put your project on hold for a little everything and get and read the chapters appropriate Web Application Construction Kit of Ben Forta. You can learn more about it here - http://www.forta.com/books/0321223675/. Once you have the concepts down, you will have a much more concentrated idea on what to do.

  • (Updated report) SQL query - may not know how to make one

    Hi people,

    Can someone tell me how to make a report where the data can be updated? Not an interactive report, SQL report that selects a single row. The only options in the menu dropdown I see are "SQL query" and 'SQL Query (body of function from PL/SQL returning SQL query)', but I have a report elsewhere that says: this type are "SQL Query (updated report)", but I do not remember how :(

    Thank you very much

    -Adam

    Hi Adam,.

    An updated report is a 'tabular form' - see: http://download.oracle.com/docs/cd/E10513_01/doc/appdev.310/e10497/frm_tabular.htm#CHDFBHDB

    Andy

  • Need help for the Partition of PL/SQL query for a question

    Hi all


    I'm running on a question that I'm not able to get the desired result. I would appreciate if one of you experts can help resolve this.

    SQL * more: Production of release 11.2.0.1.0 game 4 Feb 09:31:26 2016
    Copyright (c) 1982, 2010, Oracle.  All rights reserved.

    Connected to:
    Oracle Database 11 g Enterprise Edition Release 11.2.0.4.0 - 64 bit Production
    With partitioning, OLAP, Data Mining and Real Application Testing options


    with t as)
    Select 1 numero_enregistrement, Student_ID 123, nvl (trim (01), 'NULL') like Item_id, 'ITEM_ID_01' FIELD_NAME Union double all the
    Select 1 numero_enregistrement, Student_ID 123, nvl (trim(' '), 'NULL') like Item_id, 'ITEM_ID_02' FIELD_NAME Union double all the
    Select 1 numero_enregistrement, Student_ID 123, nvl (trim(' '), 'NULL') like Item_id, 'ITEM_ID_03' FIELD_NAME Union double all the
    Select 1 numero_enregistrement, Student_ID 123, nvl (trim(' '), 'NULL') like Item_id, 'ITEM_ID_04' FIELD_NAME Union double all the
    Select 1 numero_enregistrement, Student_ID 123, nvl (trim(' '), 'NULL') like Item_id, 'ITEM_ID_05' FIELD_NAME Union double all the
    Select 1 numero_enregistrement, Student_ID 123, nvl (trim(' '), 'NULL') like Item_id, 'ITEM_ID_06' FIELD_NAME Union double all the
    Select 2 numero_enregistrement, Student_ID 123, nvl (trim('01'), 'NULL') like Item_id, 'ITEM_ID_01' FIELD_NAME Union double all the
    Select 2 numero_enregistrement, Student_ID 123, nvl (trim('02'), 'NULL') like Item_id, 'ITEM_ID_02' FIELD_NAME Union double all the
    Select 2 numero_enregistrement, Student_ID 123, nvl (trim('03'), 'NULL') like Item_id, 'ITEM_ID_03' FIELD_NAME Union double all the
    Select 2 numero_enregistrement, Student_ID 123, nvl (trim('01'), 'NULL') like Item_id, 'ITEM_ID_04' FIELD_NAME Union double all the
    Select 2 numero_enregistrement, Student_ID 123, nvl (trim('01'), 'NULL') like Item_id, 'ITEM_ID_05' FIELD_NAME Union double all the
    Select 2 numero_enregistrement, Student_ID 123, nvl (trim('02'), 'NULL') like Item_id, 'ITEM_ID_06' double FIELD_NAME)
    SELECT distinct COUNT (*) OVER (PARTITION BY numero_enregistrement ORDER BY numero_enregistrement) REC_COUNT, numero_enregistrement, STUDENT_ID, ITEM_ID, Field_Name FROM t
    where ITEM_ID = 'NULL '.

    I get the following result.


    NUMERO_ENREGISTREMENT ITEM_ID FIELD_NAME STUDENT_ID REC_COUNT
    5                                   1                                             123                              NULL               ITEM_ID_02
    5                                   1                                             123                              NULL               ITEM_ID_03
    5                                   1                                             123                              NULL               ITEM_ID_04
    5                                   1                                             123                              NULL               ITEM_ID_05
    5                                   1                                             123                              NULL               ITEM_ID_06


    My desired output is

    Rec_COUNT Student_ID ITEM_ID FIELD_NAME numero_enregistrement
    5 1 123 NULL ITEM_ID_02, ITEM_ID_03, ITEM_ID_04, ITEM_ID_04, ITEM_ID_05

    Thanks in advance

    Rajesh

    Hi, Renon,

    Thanks for posting the sample data and results; It is very useful.

    Be sure to explain exactly how you get these results from these data.  There are many different reasons you may have, that all happen to produce the same results with the sample data you posted, but will get different results with other data sets.

    This looks like a job for aggregate (including the LISTAGG) functions and GROUP BY, not for functions, analytical and PARTITION BY

  • Please help debug a PL/SQL

    Hello

    I try to use in bulk collect to change an old PL/SQL (runs, but runs slowly).

    -the original

    DECLARE
    CURSOR C_CURSOR IS SELECT * FROM MF_S224_RPT WHERE UIDY_LO IS NOT NULL AND PATN_LIST IS NOT NULL;
    V_DEF_DATA C_CURSOR % ROWTYPE;
    str_new_uidy_lo VARCHAR2 (255);

    CURSOR C_CURSOR_LN IS SELECT * FROM MF_S224_RPT_LN WHERE UIDY_LO IS NOT NULL;
    V_DEF_DATA_LN C_CURSOR_LN % ROWTYPE;
    str_new_uidy_lo_ln VARCHAR2 (255);

    BEGIN
    C_CURSOR OPEN;
    EXTRACT THE C_CURSOR IN V_DEF_DATA;
    C_CURSOR % LOOP WHILE
    str_new_uidy_lo: = (' & 6084 &'|) V_DEF_DATA. FISC_YEAR | ' &' | V_DEF_DATA. FISC_MNTH | ' &' | V_DEF_DATA. VR | ' &' | V_DEF_DATA. BENEFITS | ' &' | V_DEF_DATA. PATN_LIST | ' &' | V_DEF_DATA. (SLA);
    UPDATE T1 SET T1 MF_S224_RPT. UIDY_LO is str_new_uidy_lo WHERE T1. UIDY_LO = V_DEF_DATA. UIDY_LO;
    UPDATE T2 T2 SET MF_S224_RPT_LN. PRPT_ID_LO is str_new_uidy_lo WHERE T2. PRPT_ID_LO = V_DEF_DATA. UIDY_LO;
    UPDATE MF_S224_RPT_ACT T5 T5 SET. PRPT_ID_LO is str_new_uidy_lo WHERE T5. PRPT_ID_LO = V_DEF_DATA. UIDY_LO;
    EXTRACT THE C_CURSOR IN V_DEF_DATA;
    END LOOP;
    CLOSE C_CURSOR;

    C_CURSOR_LN OPEN;
    EXTRACT THE C_CURSOR_LN IN V_DEF_DATA_LN;
    C_CURSOR_LN % LOOP WHILE
    str_new_uidy_lo_ln: = ('& 6085' |) SUBSTR (V_DEF_DATA_LN. PRPT_ID_LO, 6). ' &' | V_DEF_DATA_LN. TSYM | ' &' | V_DEF_DATA_LN. GLAC | ' &' | V_DEF_DATA_LN. ACMP_YEAR | ' &' | V_DEF_DATA_LN. ACMP_MNTH | ' &' | V_DEF_DATA_LN. RCPT_DISB_IN | ' &' | V_DEF_DATA_LN. PATN);
    UPDATE MF_S224_RPT_LN SET T3 T3. UIDY_LO is str_new_uidy_lo_ln WHERE T3. UIDY_LO = V_DEF_DATA_LN. UIDY_LO;
    UPDATE MF_S224_RPT_ACT SET T4 T4. PRPT_LINE_ID_LO is str_new_uidy_lo_ln WHERE T4. PRPT_LINE_ID_LO = V_DEF_DATA_LN. UIDY_LO;
    EXTRACT THE C_CURSOR_LN IN V_DEF_DATA_LN;
    END LOOP;
    CLOSE C_CURSOR_LN;

    END;
    /

    -Change, to help collect in bulk

    DECLARE

    CURSOR C_CURSOR IS SELECT * FROM MF_S224_RPT WHERE UIDY_LO IS NOT NULL AND PATN_LIST IS NOT NULL;
    TYPE of c_arr1 IS the TABLE OF C_CURSOR % ROWTYPE;
    c_rows1 c_arr1;
    str_new_uidy_lo VARCHAR2 (500);

    CURSOR C_CURSOR_LN IS SELECT * FROM MF_S224_RPT_LN WHERE UIDY_LO IS NOT NULL;
    TYPE of c_arr2 IS the TABLE OF C_CURSOR_LN % ROWTYPE;
    c_rows2 c_arr2;
    str_new_uidy_lo_ln VARCHAR2 (500);


    BEGIN
    C_CURSOR OPEN;
    EXTRACT the C_CURSOR BULK COLLECT INTO c_rows1 LIMIT 2000;
    FORALL i IN c_rows1. FIRST... c_rows1. LAST
    str_new_uidy_lo: = (' & 6084 &'| c_rows1 (i).) FISC_YEAR | ' &' | c_rows1 (i). FISC_MNTH | ' &' | c_rows1 (i). VR | ' &' | c_rows1 (i). BENEFITS | ' &' | c_rows1 (i). PATN_LIST | ' &' | c_rows1 (i). (SLA);
    UPDATE T1 SET T1 MF_S224_RPT. UIDY_LO is str_new_uidy_lo WHERE T1. UIDY_LO = c_rows1 (i). UIDY_LO;
    UPDATE T2 T2 SET MF_S224_RPT_LN. PRPT_ID_LO is str_new_uidy_lo WHERE T2. PRPT_ID_LO = c_rows1 (i). UIDY_LO;
    UPDATE MF_S224_RPT_ACT T5 T5 SET. PRPT_ID_LO is str_new_uidy_lo WHERE T5. PRPT_ID_LO = c_rows1 (i). UIDY_LO;
    WHEN c_rows1 EXIT. COUNTY, 2000;
    END LOOP;
    CLOSE C_CURSOR;

    C_CURSOR_LN OPEN;
    EXTRACT the C_CURSOR_LN BULK COLLECT INTO c_rows2 LIMIT 2000;
    FORALL i IN c_rows2. FIRST... c_rows2. LAST
    str_new_uidy_lo_ln: = ('& 6085' |) SUBSTR (c_rows2 (i). PRPT_ID_LO, 6). ' &' | c_rows2 (i). TSYM | ' &' | c_rows2 (i). GLAC | ' &' | c_rows2 (i). ACMP_YEAR | ' &' | c_rows2 (i). ACMP_MNTH | ' &' | c_rows2 (i). RCPT_DISB_IN | ' &' | c_rows2 (i). PATN);
    UPDATE MF_S224_RPT_LN SET T3 T3. UIDY_LO is str_new_uidy_lo_ln WHERE T3. UIDY_LO = c_rows2 (i). UIDY_LO;
    UPDATE MF_S224_RPT_ACT SET T4 T4. PRPT_LINE_ID_LO is str_new_uidy_lo_ln WHERE T4. PRPT_LINE_ID_LO = c_rows2 (i). UIDY_LO;
    WHEN c_rows2 EXIT. COUNTY, 2000;
    END LOOP;
    CLOSE C_CURSOR_LN;

    END;
    /

    (although, error)

    Error report:
    ORA-06550: line 18, column 3:
    PLS-00103: encountered the symbol "STR_NEW_UIDY_LO" during the expected in the following way:

    . (* @ % & -+ / to rest rem mod select update with)
    < an exponent (*) > remove insert | run save type multiset
    Fusion
    ORA-06550: line 18, column 172:
    PLS-00103: encountered the symbol ";" when expecting one of the following values:

    ), * & = - + <>/ is mod remains not rem
    < an exponent (*) > <>or! = or ~ = > = < = <>and like2 or
    like4 likec between duplication | multise
    ORA-06550: line 24, column 3:
    PLS-00103: encountered the symbol "CLOSE" when expecting one of the following conditions:

    not end up dominant static of final instantiable order pragma
    manufacturer membership card
    ORA-06550: line 29, column 7:
    PLS-00103: encountered the symbol "STR_NEW_UIDY_LO_LN" during the expected in the following way:

    . (* @ % & -+ / to rest rem mod select update with)
    < an exponent (*) > remove insert | run save type multiset
    Fusion
    ORA-06550: line 29, column 221:
    PLS-00103: encountered the symbol ";" when expecting one of the following values:

    ), * & = - + <>/ is mod remains not rem
    < an exponent (*) > <>or! = or ~ = > = < = <>and like2 or
    like4 likec between duplication | multise
    ORA-06550: line 34, column 3:
    PLS-00103: encountered the symbol "CLOSE" when expecting one of the following conditions:

    not end up dominant static of final instantiable order pragma
    manufacturer membership card
    06550 00000 - "line %s, column % s:\n%s".
    * Cause: Usually a PL/SQL compilation error.
    * Action:

    I don't see anything wrong yet... could you help take a look?

    Thank you very much!!!

    DECLARE
    
       CURSOR c_cursor IS
          SELECT *
            FROM mf_s224_rpt
           WHERE uidy_lo IS NOT NULL
             AND patn_list IS NOT NULL;
    
       TYPE c_arr1 IS TABLE OF c_cursor%ROWTYPE;
    
       c_rows1 c_arr1;
       str_new_uidy_lo VARCHAR2(500);
    
       CURSOR c_cursor_ln IS
          SELECT *
            FROM mf_s224_rpt_ln
           WHERE uidy_lo IS NOT NULL;
    
       TYPE c_arr2 IS TABLE OF c_cursor_ln%ROWTYPE;
    
       c_rows2 c_arr2;
       str_new_uidy_lo_ln VARCHAR2(500);
    
    BEGIN
    
       OPEN c_cursor;
    
       FETCH c_cursor
        BULK COLLECT
        INTO c_rows1
       LIMIT 2000;
    
       FORALL i IN c_rows1.FIRST .. c_rows1.LAST 
    
          UPDATE mf_s224_rpt t1
             SET t1.uidy_lo = str_new_uidy_lo
           WHERE t1.uidy_lo = c_rows1(i).uidy_lo;
    
          UPDATE mf_s224_rpt_ln t2
             SET t2.prpt_id_lo = str_new_uidy_lo
           WHERE t2.prpt_id_lo = c_rows1(i).uidy_lo;
    
          UPDATE mf_s224_rpt_act t5
             SET t5.prpt_id_lo = str_new_uidy_lo
           WHERE t5.prpt_id_lo = c_rows1(i).uidy_lo; 
    
          --EXIT WHEN c_rows1.COUNT < 2000;
    
          --END LOOP;
    
          str_new_uidy_lo :=('&6084&'||c_rows1(i).fisc_year||'&'||c_rows1(i).fisc_mnth||'&'||c_rows1(i).vrsn||'&'||c_rows1(i).agcy||'&'||c_rows1(i).patn_list||'&'||c_rows1(i).alc);
    
      CLOSE c_cursor;
    
      OPEN c_cursor_ln;
    
      FETCH c_cursor_ln
       BULK COLLECT
       INTO c_rows2
      LIMIT 2000;
    
      FORALL i IN c_rows2.FIRST..c_rows2.LAST
    
         UPDATE mf_s224_rpt_ln t3
            SET t3.uidy_lo = str_new_uidy_lo_ln
          WHERE t3.uidy_lo = c_rows2(i).uidy_lo;
    
         UPDATE mf_s224_rpt_act t4
            SET t4.prpt_line_id_lo = str_new_uidy_lo_ln
          WHERE t4.prpt_line_id_lo = c_rows2(i).uidy_lo;
    
         --EXIT WHEN c_rows2.COUNT < 2000;
         --END LOOP;
         str_new_uidy_lo_ln :=('&6085'||SUBSTR(c_rows2(i).prpt_id_lo, 6)||'&'||c_rows2(i).tsym||'&'||c_rows2(i).glac||'&'||c_rows2(i).acmp_year||'&'||c_rows2(i).acmp_mnth||'&'||c_rows2(i).rcpt_disb_in||'&'||c_rows2(i).patn);
    
      CLOSE c_cursor_ln;
    
    END;
    

    A FORALL statement submit your statement number 'x' DML time all of a sudden.  Why do you 2 UPDATE instructions, I'm not sure.  But also your assignment to a string variable cannot be fair after the FORALL as it is NOT a loop.

  • Help setting up a SQL query with poor performance

    Hi all

    Database version: 10.2.0.5

    I'm working on a new report to view the top users by the number of calls. The table is truncated and filled again every month with records for the previous month; It contains approximately 400 000 records.

    I created a view with the columns needed for the report; also, the two functions of view calls to determine if a phone number is assigned to multiple staffs or several departments.

    It's full again table every month:

     CREATE TABLE "VOIP"."MONTHLY_BILLING_DETAILS" 
       (    "ID" NUMBER NOT NULL ENABLE, 
        "CDRRECORDTYPE" NUMBER, 
        "G_CALLMANAGERID" NUMBER, 
        "G_CALLID" NUMBER, 
        "O_LEGCALLIDENTIFIER" NUMBER, 
        "DATETIMEORIGINATION" NUMBER, 
        "O_NODEID" NUMBER, 
        "O_SPAN" NUMBER, 
        "O_IPADDR" NUMBER, 
        "CALLINGPARTYNUMBER" VARCHAR2(50 BYTE) NOT NULL ENABLE, 
        "CALLINGPARTY_USERID" VARCHAR2(128 BYTE), 
        "O_CAUSE_LOCATION" NUMBER, 
        "O_CAUSE_VALUE" NUMBER, 
        "O_PRECEDENCELEVEL" NUMBER, 
        "O_MEDIATRANSPORTADDR_IP" NUMBER, 
        "O_MEDIATRANSPORTADDR_PORT" NUMBER, 
        "O_MCAP_PAYLOADCAPABILITY" NUMBER, 
        "O_MCAP_MAXFRAMESPERPACKET" NUMBER, 
        "O_MCAP_G723BITRATE" NUMBER, 
        "O_VCAP_CODEC" NUMBER, 
        "O_VCAP_BANDWIDTH" NUMBER, 
        "O_VCAP_RESOLUTION" NUMBER, 
        "O_VIDEOTRANSPORTADDR_IP" NUMBER, 
        "O_VIDEOTRANSPORTADDR_PORT" NUMBER, 
        "O_RSVPAUDIOSTAT" VARCHAR2(64 BYTE), 
        "O_RSVPVIDEOSTAT" VARCHAR2(64 BYTE), 
        "DESTLEGIDENTIFIER" NUMBER, 
        "DESTNODEID" NUMBER, 
        "DESTSPAN" NUMBER, 
        "DESTIPADDR" NUMBER, 
        "ORIGINALCALLEDPARTYNUMBER" VARCHAR2(50 BYTE), 
        "FINALC_PARTYNUMBER" VARCHAR2(50 BYTE), 
        "FINALC_PARTY_USERID" VARCHAR2(128 BYTE), 
        "DESTCAUSE_LOCATION" NUMBER, 
        "DESTCAUSE_VALUE" NUMBER, 
        "DESTPRECEDENCELEVEL" NUMBER, 
        "DESTMEDIATRANSPORTADDR_IP" NUMBER, 
        "DESTMEDIATRANSPORTADDR_PORT" NUMBER, 
        "DESTMCAP_PAYLOADCAPABILITY" NUMBER, 
        "DESTMCAP_MAXFRAMESPERPACKET" NUMBER, 
        "DESTMCAP_G723BITRATE" NUMBER, 
        "DV_CAP_CODEC" NUMBER, 
        "DV_CAP_BANDWIDTH" NUMBER, 
        "DV_CAP_RESOLUTION" NUMBER, 
        "DV_TRANSPORTADDR_IP" NUMBER, 
        "DV_TRANSPORTADDR_PORT" NUMBER, 
        "DESTRSVPAUDIOSTAT" VARCHAR2(64 BYTE), 
        "DESTRSVPVIDEOSTAT" VARCHAR2(64 BYTE), 
        "DATETIMECONNECT" NUMBER, 
        "DATETIMEDISCONNECT" NUMBER, 
        "LASTREDIRECTDN" VARCHAR2(50 BYTE), 
        "PKID" VARCHAR2(4000 BYTE), 
        "O_INALCALLEDPARTYNUM_PARTITION" VARCHAR2(50 BYTE), 
        "CALLINGPARTYNUM_PARTITION" VARCHAR2(50 BYTE), 
        "FINALC_PARTYNUM_PARTITION" VARCHAR2(50 BYTE), 
        "LASTREDIRECTDNPARTITION" VARCHAR2(50 BYTE), 
        "DURATION" NUMBER, 
        "O_DEVICENAME" VARCHAR2(129 BYTE), 
        "DESTDEVICENAME" VARCHAR2(129 BYTE), 
        "O_CALLTERMINATION_BEHALF" NUMBER, 
        "DESTCALLTERMINATION_BEHALF" NUMBER, 
        "O_CALLEDPARTYREDIRECT_BEHALF" NUMBER, 
        "LASTREDIRECTREDIRECT_BEHALF" NUMBER, 
        "O_CALLEDPARTYREDIRECTREASON" NUMBER, 
        "LASTREDIRECTREDIRECTREASON" NUMBER, 
        "DESTCONVERSATIONID" NUMBER, 
        "G_CALLID_CLUSTERID" VARCHAR2(50 BYTE), 
        "JOIN_BEHALF" NUMBER, 
        "COMMENTS" VARCHAR2(2048 BYTE), 
        "AUTHCODEDESCRIPTION" VARCHAR2(50 BYTE), 
        "AUTHORIZATIONLEVEL" NUMBER, 
        "CLIENTMATTERCODE" VARCHAR2(32 BYTE), 
        "O_DTMFMETHOD" NUMBER, 
        "DESTDTMFMETHOD" NUMBER, 
        "CALLSECUREDSTATUS" NUMBER, 
        "O_CONVERSATIONID" NUMBER, 
        "O_MCAP_BANDWIDTH" NUMBER, 
        "DESTMCAP_BANDWIDTH" NUMBER, 
        "AUTHORIZATIONCODEVALUE" VARCHAR2(32 BYTE), 
        "OUTPULSEDCALLINGPARTYNUMBER" VARCHAR2(50 BYTE), 
        "OUTPULSEDCALLEDPARTYNUMBER" VARCHAR2(50 BYTE), 
        "O_IPV4V6ADDR" VARCHAR2(64 BYTE), 
        "DESTIPV4V6ADDR" VARCHAR2(64 BYTE), 
        "O_VCAP_CODEC_CHAN2" NUMBER, 
        "O_VCAP_BANDWIDTH_CHAN2" NUMBER, 
        "O_VCAP_RESOLUTION_CHAN2" NUMBER, 
        "O_V_TRANSPORTADDR_IP_CHAN2" NUMBER, 
        "O_V_TRANSPORTADDR_PORT_CHAN2" NUMBER, 
        "O_V_OCHANNEL_ROLE_CHAN2" NUMBER, 
        "DV_CAP_CODEC_CHAN2" NUMBER, 
        "DV_CAP_BANDWIDTH_CHAN2" NUMBER, 
        "DV_CAP_RESOLUTION_CHAN2" NUMBER, 
        "DV_TRANSPORTADDR_IP_CHAN2" NUMBER, 
        "DV_TRANSPORTADDR_PORT_CHAN2" NUMBER, 
        "DV_CHANNEL_ROLE_CHAN2" NUMBER, 
        "DATE_CREATED" DATE, 
        "DATETIME_CONNECT" DATE, 
        "DATETIME_DISCONNECT" DATE, 
        "USERID_EMAIL_ADDRESS" VARCHAR2(100 BYTE), 
        "FROM_FULL_TELEPHONE" VARCHAR2(20 BYTE), 
        "TO_FULL_TELEPHONE" VARCHAR2(20 BYTE), 
        "FROM_EXCHANGE" VARCHAR2(7 BYTE), 
        "TO_EXCHANGE" VARCHAR2(20 BYTE), 
        "FROM_CITY" VARCHAR2(200 BYTE), 
        "FROM_STATE" VARCHAR2(2 BYTE), 
        "TO_CITY" VARCHAR2(200 BYTE), 
        "TO_STATE" VARCHAR2(2 BYTE), 
        "CALL_TYPE" VARCHAR2(10 BYTE), 
         CONSTRAINT "MONTHLY_BILLING_PK" PRIMARY KEY ("ID")
      USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 3145728 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA"  ENABLE
       ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
      STORAGE(INITIAL 75497472 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX1" ON "VOIP"."MONTHLY_BILLING_DETAILS" (TRUNC("DATETIME_CONNECT")) 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 4194304 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX10" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("CALL_TYPE") 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 4194304 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX2" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("FROM_EXCHANGE") 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 3145728 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX3" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("FROM_FULL_TELEPHONE", TRUNC("DATETIME_CONNECT")) 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX4" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("DATETIME_CONNECT", NVL("FROM_FULL_TELEPHONE","CALLINGPARTYNUMBER")) 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 5242880 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX5" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("DATETIME_CONNECT", NVL("TO_FULL_TELEPHONE","ORIGINALCALLEDPARTYNUMBER")) 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 5242880 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX6" ON "VOIP"."MONTHLY_BILLING_DETAILS" (TO_CHAR("DATETIME_CONNECT",'fmMONTH YYYY')) 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 4194304 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX7" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("TO_EXCHANGE") 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 3145728 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX8" ON "VOIP"."MONTHLY_BILLING_DETAILS" (NVL("FROM_FULL_TELEPHONE","CALLINGPARTYNUMBER")) 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 4194304 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX9" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("DATETIME_CONNECT") 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 3145728 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    

    These are the functions to determine if a phone number is assigned to multiple staffs or departments:

    FUNCTION GET_EMPLOYEE_NAME (P_FROM_FULL_TELEPHONE IN VARCHAR2)
    RETURN VARCHAR2
    AS
      L_NAME EMPLOYEES.NAME%TYPE;
    BEGIN
      SELECT NAME
      INTO L_NAME
      FROM EMPLOYEES
      WHERE WORK_PHONE_1_FORMAT = P_FROM_FULL_TELEPHONE;
      
      RETURN L_NAME;
    EXCEPTION
      WHEN TOO_MANY_ROWS THEN
        L_NAME := 'Multiple Employees';
        RETURN L_NAME;
      WHEN NO_DATA_FOUND THEN
        L_NAME := 'No Employee Assigned';
        RETURN L_NAME;
      WHEN OTHERS THEN
        NULL;
    END;
    

    FUNCTION GET_DEPARTMENT_NAME (P_FROM_FULL_TELEPHONE IN VARCHAR2)
    RETURN VARCHAR2
    AS
      L_DEPT_DESCR EMPLOYEES.DEPT_DESCR%TYPE;
    BEGIN
      SELECT DEPT_DESCR
      INTO L_DEPT_DESCR
      FROM EMPLOYEES
      WHERE WORK_PHONE_1_FORMAT = P_FROM_FULL_TELEPHONE;
      
      RETURN L_DEPT_DESCR;
    EXCEPTION
      WHEN TOO_MANY_ROWS THEN
        L_DEPT_DESCR := 'Multiple Departments';
        RETURN L_DEPT_DESCR;
      WHEN NO_DATA_FOUND THEN
        L_DEPT_DESCR := 'No Department Assigned';
        RETURN L_DEPT_DESCR;
      WHEN OTHERS THEN
        NULL;
    END;
    

    This is the point of view that I'll use in the report:

    CREATE OR REPLACE FORCE VIEW "VOIP"."TOP_USERS_BY_CALLS_V" ("TOP_NO", "EMPLOYEE_NAME", "EMPLOYEE_DEPARTMENT", "PHONE_NUMBER", "QUANTITY_CALLS") AS 
      SELECT
      ROWNUM,
      VOIP_PKG.GET_EMPLOYEE_NAME(FROM_FULL_TELEPHONE),
      VOIP_PKG.GET_DEPARTMENT_NAME(FROM_FULL_TELEPHONE),
      FROM_FULL_TELEPHONE,
      QUANTITY_CALLS
    FROM (
    SELECT
      MBD.FROM_FULL_TELEPHONE,
      COUNT(1) QUANTITY_CALLS
    FROM
      MONTHLY_BILLING_DETAILS MBD
    WHERE
      MBD.FROM_FULL_TELEPHONE IS NOT NULL                                     AND
      MBD.FROM_FULL_TELEPHONE <> '000-000-0000'                               AND
      LENGTH(MBD.FROM_FULL_TELEPHONE) = 12                                    AND
      LENGTH(MBD.TO_FULL_TELEPHONE) = 12                                      AND
      SUBSTR(MBD.TO_FULL_TELEPHONE,1,3) NOT IN (SELECT AREA_CODE
                                                FROM NYNJ_METRO_AREA_CODES)   AND
      SUBSTR(MBD.TO_FULL_TELEPHONE,1,3) NOT IN ('800','822','833','844',
                                                '855','866','877','888')
    GROUP BY
      MBD.FROM_FULL_TELEPHONE
    ORDER BY
      QUANTITY_CALLS DESC
    )
    WHERE ROWNUM <= 100;
    

    Explain Plan output and Extended SQL Trace:


    SQL> 
    SQL> show parameter user_dump_dest
    
    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- ------------------------------
    user_dump_dest                       string      D:\ORACLEHOMES\ADMIN\RTS9\UDUM
                                                     P
    SQL> 
    SQL> show parameter optimizer
    
    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- ------------------------------
    optimizer_dynamic_sampling           integer     2
    optimizer_features_enable            string      10.2.0.5
    optimizer_index_caching              integer     0
    optimizer_index_cost_adj             integer     100
    optimizer_mode                       string      ALL_ROWS
    optimizer_secure_view_merging        boolean     TRUE
    SQL> 
    SQL> show parameter db_file_multi
    
    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- ------------------------------
    db_file_multiblock_read_count        integer     16
    SQL> 
    SQL> show parameter db_block_size
    
    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- ------------------------------
    db_block_size                        integer     8192
    SQL> 
    SQL> show parameter cursor_sharing
    
    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- ------------------------------
    cursor_sharing                       string      EXACT
    SQL> 
    SQL> column sname format a20
    SQL> column pname format a20
    SQL> column pval2 format a20
    SQL> 
    SQL> select
      2  sname
      3  , pname
      4  , pval1
      5  , pval2
      6  from
      7  sys.aux_stats$;
    
    SNAME                PNAME                     PVAL1 PVAL2
    -------------------- -------------------- ---------- --------------------
    SYSSTATS_INFO        STATUS                          COMPLETED
    SYSSTATS_INFO        DSTART                          02-09-2009 15:46
    SYSSTATS_INFO        DSTOP                           02-09-2009 15:46
    SYSSTATS_INFO        FLAGS                         1
    SYSSTATS_MAIN        CPUSPEEDNW            1259.6206
    SYSSTATS_MAIN        IOSEEKTIM                    10
    SYSSTATS_MAIN        IOTFRSPEED                 4096
    SYSSTATS_MAIN        SREADTIM
    SYSSTATS_MAIN        MREADTIM
    SYSSTATS_MAIN        CPUSPEED
    SYSSTATS_MAIN        MBRC
    SYSSTATS_MAIN        MAXTHR
    SYSSTATS_MAIN        SLAVETHR
    
    13 rows selected.
    
    Elapsed: 00:00:00.03
    SQL> 
    SQL> explain plan for
      2  SELECT
      3    TOP_NO,
      4    EMPLOYEE_NAME,
      5    EMPLOYEE_DEPARTMENT,
      6    PHONE_NUMBER,
      7    QUANTITY_CALLS
      8  FROM
      9    TOP_USERS_BY_CALLS_V
     10  ORDER BY
     11    QUANTITY_CALLS DESC;
    
    Explained.
    
    Elapsed: 00:00:00.18
    SQL> 
    SQL> select * from table(dbms_xplan.display);
    
    PLAN_TABLE_OUTPUT
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Plan hash value: 826236322
    
    ----------------------------------------------------------------------------------------------------------------
    | Id  | Operation                          | Name                      | Rows  | Bytes | Cost (%CPU)| Time     |
    ----------------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT                   |                           |     1 |  4042 |  1313   (1)| 00:00:16 |
    |   1 |  SORT ORDER BY                     |                           |     1 |  4042 |  1313   (1)| 00:00:16 |
    |   2 |   VIEW                             | TOP_USERS_BY_CALLS_V      |     1 |  4042 |  1312   (1)| 00:00:16 |
    |*  3 |    COUNT STOPKEY                   |                           |       |       |            |          |
    |   4 |     VIEW                           |                           |     1 |    25 |  1312   (1)| 00:00:16 |
    |*  5 |      SORT ORDER BY STOPKEY         |                           |     1 |    26 |  1312   (1)| 00:00:16 |
    |   6 |       HASH GROUP BY                |                           |     1 |    26 |  1312   (1)| 00:00:16 |
    |*  7 |        FILTER                      |                           |       |       |            |          |
    |*  8 |         TABLE ACCESS BY INDEX ROWID| MONTHLY_BILLING_DETAILS   |     1 |    26 |  1310   (1)| 00:00:16 |
    |*  9 |          INDEX FULL SCAN           | MONTHLY_BILL_INDEX3       |   934 |       |   449   (1)| 00:00:06 |
    |* 10 |         INDEX FULL SCAN            | NYNJ_METRO_AREA_CODES_UK1 |     1 |     4 |     1   (0)| 00:00:01 |
    ----------------------------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       3 - filter(ROWNUM<=100)
       5 - filter(ROWNUM<=100)
       7 - filter( NOT EXISTS (SELECT 0 FROM VOIP."NYNJ_METRO_AREA_CODES" "NYNJ_METRO_AREA_CODES" WHERE
                  LNNVL("AREA_CODE"<>SUBSTR(:B1,1,3))))
       8 - filter(LENGTH("MBD"."TO_FULL_TELEPHONE")=12 AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'800' AND
                  SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'822' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'833' AND
                  SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'844' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'855' AND
                  SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'866' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'877' AND
                  SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'888')
       9 - filter(LENGTH("MBD"."FROM_FULL_TELEPHONE")=12 AND "MBD"."FROM_FULL_TELEPHONE"<>'000-000-0000'
                  AND "MBD"."FROM_FULL_TELEPHONE" IS NOT NULL)
      10 - filter(LNNVL("AREA_CODE"<>SUBSTR(:B1,1,3)))
    
    33 rows selected.
    
    Elapsed: 00:00:00.82
    SQL> 
    SQL> rollback;
    
    Rollback complete.
    
    Elapsed: 00:00:00.00
    SQL> 
    SQL> set autotrace traceonly arraysize 100
    SQL> 
    SQL> alter session set tracefile_identifier = 'mytrace1';
    
    Session altered.
    
    Elapsed: 00:00:00.01
    SQL> 
    SQL> alter session set events '10046 trace name context forever, level 8';
    
    Session altered.
    
    Elapsed: 00:00:00.15
    SQL> 
    SQL> SELECT
      2    TOP_NO,
      3    EMPLOYEE_NAME,
      4    EMPLOYEE_DEPARTMENT,
      5    PHONE_NUMBER,
      6    QUANTITY_CALLS
      7  FROM
      8    TOP_USERS_BY_CALLS_V
      9  ORDER BY
     10    QUANTITY_CALLS DESC;
    
    100 rows selected.
    
    Elapsed: 00:10:37.68
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 826236322
    
    ----------------------------------------------------------------------------------------------------------------
    | Id  | Operation                          | Name                      | Rows  | Bytes | Cost (%CPU)| Time     |
    ----------------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT                   |                           |     1 |  4042 |  1313   (1)| 00:00:16 |
    |   1 |  SORT ORDER BY                     |                           |     1 |  4042 |  1313   (1)| 00:00:16 |
    |   2 |   VIEW                             | TOP_USERS_BY_CALLS_V      |     1 |  4042 |  1312   (1)| 00:00:16 |
    |*  3 |    COUNT STOPKEY                   |                           |       |       |            |          |
    |   4 |     VIEW                           |                           |     1 |    25 |  1312   (1)| 00:00:16 |
    |*  5 |      SORT ORDER BY STOPKEY         |                           |     1 |    26 |  1312   (1)| 00:00:16 |
    |   6 |       HASH GROUP BY                |                           |     1 |    26 |  1312   (1)| 00:00:16 |
    |*  7 |        FILTER                      |                           |       |       |            |          |
    |*  8 |         TABLE ACCESS BY INDEX ROWID| MONTHLY_BILLING_DETAILS   |     1 |    26 |  1310   (1)| 00:00:16 |
    |*  9 |          INDEX FULL SCAN           | MONTHLY_BILL_INDEX3       |   934 |       |   449   (1)| 00:00:06 |
    |* 10 |         INDEX FULL SCAN            | NYNJ_METRO_AREA_CODES_UK1 |     1 |     4 |     1   (0)| 00:00:01 |
    ----------------------------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       3 - filter(ROWNUM<=100)
       5 - filter(ROWNUM<=100)
       7 - filter( NOT EXISTS (SELECT 0 FROM VOIP."NYNJ_METRO_AREA_CODES" "NYNJ_METRO_AREA_CODES" WHERE
                  LNNVL("AREA_CODE"<>SUBSTR(:B1,1,3))))
       8 - filter(LENGTH("MBD"."TO_FULL_TELEPHONE")=12 AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'800' AND
                  SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'822' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'833' AND
                  SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'844' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'855' AND
                  SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'866' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'877' AND
                  SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'888')
       9 - filter(LENGTH("MBD"."FROM_FULL_TELEPHONE")=12 AND "MBD"."FROM_FULL_TELEPHONE"<>'000-000-0000'
                  AND "MBD"."FROM_FULL_TELEPHONE" IS NOT NULL)
      10 - filter(LNNVL("AREA_CODE"<>SUBSTR(:B1,1,3)))
    
    
    Statistics
    ----------------------------------------------------------
            365  recursive calls
              0  db block gets
         689543  consistent gets
         212906  physical reads
              0  redo size
           5984  bytes sent via SQL*Net to client
            400  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              2  sorts (memory)
              0  sorts (disk)
            100  rows processed
    
    SQL> 
    SQL> disconnect
    

    Part of the automatic trace output:

    SELECT
      TOP_NO,
      EMPLOYEE_NAME,
      EMPLOYEE_DEPARTMENT,
      PHONE_NUMBER,
      QUANTITY_CALLS
    FROM
      TOP_USERS_BY_CALLS_V
    ORDER BY
      QUANTITY_CALLS DESC
    
    call     count       cpu    elapsed       disk      query    current        rows
    ------- ------  -------- ---------- ---------- ---------- ----------  ----------
    Parse        1      0.00       0.43          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        2     24.70     635.81     212587     631823          0         100
    ------- ------  -------- ---------- ---------- ---------- ----------  ----------
    total        4     24.70     636.25     212587     631823          0         100
    
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 148  
    
    Rows     Row Source Operation
    -------  ---------------------------------------------------
        100  SORT ORDER BY (cr=689531 pr=212900 pw=0 time=636823070 us)
        100   VIEW  TOP_USERS_BY_CALLS_V (cr=689531 pr=212900 pw=0 time=642681672 us)
        100    COUNT STOPKEY (cr=631823 pr=212587 pw=0 time=635667026 us)
        100     VIEW  (cr=631823 pr=212587 pw=0 time=635666810 us)
        100      SORT ORDER BY STOPKEY (cr=631823 pr=212587 pw=0 time=635666493 us)
       2512       HASH GROUP BY (cr=631823 pr=212587 pw=0 time=635666125 us)
      27112        FILTER  (cr=631823 pr=212587 pw=0 time=519230237 us)
     315563         TABLE ACCESS BY INDEX ROWID MONTHLY_BILLING_DETAILS (cr=381523 pr=212587 pw=0 time=580209555 us)
     394473          INDEX FULL SCAN MONTHLY_BILL_INDEX3 (cr=2679 pr=2679 pw=0 time=26793918 us)(object id 206675)
     226627         INDEX FULL SCAN NYNJ_METRO_AREA_CODES_UK1 (cr=250300 pr=0 pw=0 time=3575488 us)(object id 206605)
    
    
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                       2        0.00          0.00
      db file sequential read                    212587        0.20        611.67
      SQL*Net message from client                     2        0.00          0.00
      SQL*Net more data to client                     2        0.00          0.00
    ********************************************************************************
    

    DBMS_XPLAN. Output DISPLAY_CURSOR:

    SQL> 
    SQL> select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
    
    PLAN_TABLE_OUTPUT
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    SQL_ID  1ut636vt58jdw, child number 0
    -------------------------------------
    SELECT /*+ gather_plan_statistics */   TOP_NO,   EMPLOYEE_NAME,   EMPLOYEE_DEPARTMENT,   PHONE_NUMBER,   QUANTITY_CALLS FROM   TOP_USERS_BY_CALLS_V
    ORDER BY   QUANTITY_CALLS DESC
    
    Plan hash value: 826236322
    
    --------------------------------------------------------------------------------------------------------------------------------------------------------------
    | Id  | Operation                          | Name                      | Starts | E-Rows | A-Rows |   A-Time   | Buffers | Reads  |  OMem |  1Mem | Used-Mem |
    --------------------------------------------------------------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT                   |                           |      1 |        |    100 |00:09:56.06 |     689K|    210K|       |       |          |
    |   1 |  SORT ORDER BY                     |                           |      1 |      1 |    100 |00:09:56.06 |     689K|    210K| 13312 | 13312 |12288  (0)|
    |   2 |   VIEW                             | TOP_USERS_BY_CALLS_V      |      1 |      1 |    100 |00:10:04.98 |     689K|    210K|       |       |          |
    |*  3 |    COUNT STOPKEY                   |                           |      1 |        |    100 |00:09:54.89 |     631K|    210K|       |       |          |
    |   4 |     VIEW                           |                           |      1 |      1 |    100 |00:09:54.89 |     631K|    210K|       |       |          |
    |*  5 |      SORT ORDER BY STOPKEY         |                           |      1 |      1 |    100 |00:09:54.88 |     631K|    210K|  6144 |  6144 | 6144  (0)|
    |   6 |       HASH GROUP BY                |                           |      1 |      1 |   2512 |00:09:54.88 |     631K|    210K|   821K|   821K| 1153K (0)|
    |*  7 |        FILTER                      |                           |      1 |        |  27112 |00:08:58.57 |     631K|    210K|       |       |          |
    |*  8 |         TABLE ACCESS BY INDEX ROWID| MONTHLY_BILLING_DETAILS   |      1 |      1 |    315K|00:08:57.07 |     381K|    210K|       |       |          |
    |*  9 |          INDEX FULL SCAN           | MONTHLY_BILL_INDEX3       |      1 |    934 |    394K|00:00:23.02 |    2679 |   2679 |       |       |          |
    |* 10 |         INDEX FULL SCAN            | NYNJ_METRO_AREA_CODES_UK1 |    250K|      1 |    226K|00:00:03.47 |     250K|      0 |       |       |          |
    --------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       3 - filter(ROWNUM<=100)
       5 - filter(ROWNUM<=100)
       7 - filter( IS NULL)
       8 - filter((LENGTH("MBD"."TO_FULL_TELEPHONE")=12 AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'800' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'822'
                  AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'833' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'844' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'855'
                  AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'866' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'877' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'888'))
       9 - filter((LENGTH("MBD"."FROM_FULL_TELEPHONE")=12 AND "MBD"."FROM_FULL_TELEPHONE"<>'000-000-0000' AND "MBD"."FROM_FULL_TELEPHONE" IS NOT NULL))
      10 - filter(LNNVL("AREA_CODE"<>SUBSTR(:B1,1,3)))
    
    
    35 rows selected.
    
    Elapsed: 00:00:00.50
    SQL> 
    SQL> spool off
    
    

    Any help will be greatly appreciated. Please let me know if you need additional information.

    Thank you

    Erick

    ediazjorge wrote:

    Please let me know if you need additional information or do additional tests.

    Thanks again!

    Erick

    It's to you if you are satisfied or interested in improvements (if possible).

    If so the first thing I would like if you had your refreshed perspective as advised. According to expected area_code table cardinalities I doubt.

    So, if not cool off with dbms_stats.gather_table_stats on two tables, area_codes and MONTHLY_BILLING_DETAILS.

    Bottlenecks are now obviously the full table of MONTHLY_BILLING_DETAILS as well as the ANTI of LOOPS IMBRIQUEES scan.

    At the moment I don't think that an index of MONTHLY_BILLING_DETAILS will help a lot, because most of the lines will pass filter predicates, and because we need some columns in it, I have now I there will be gain a full index scan.

    I was surprissed that the optimizer pushes the substr <> predicates to both tables.

    So depending on your data, you might try

    1 make a factory of subquery select the two MONTHLY_BILLING_DETAILS columns that all directly apply predicates of membership and use it directly in the join instead of the table.

    or

    2. If all subtr to so are part of the table area_code choose in it using a subquery (or inline view) plant excluding these values.

    Both are attempts to get rid of the substr excluding as filters of join predicates.

    In fact, I was expecting a hash join anti as shown in the plan to explain instead of the nested loops anti, I expect to be more effective in this case.

    Perhaps with correct cardinalities the optimizier would understand himself.

    Just to test it, you can try the use_hash hint in the join:

    Select / * + USE_HASH (MBD, one) * /.

    ..

    OF MONTHLY_BILLING_DETAILS MBD,.

    NYNJ_METRO_AREA_CODES one

    (It's a good habit anyway usually use aliases and precede the names of columns. In the, it is easier to read queries are only trivial).

  • Classic report SQL with BLOB column not refreshing with jQuery Trigger Apexrefresh call

    Hello

    Really hoping that someone can help me, but for some reason that I try to report updated in dynamic Action to help:

    jQuery('#my-report').trigger('apexrefresh');

    on a simple SQL query report classic. I have used this many times on other parts of the report but the only difference with the report region where it is not refreshing, is that the table contains a BLOB column as it is essentially a report of downloaded files that users have made to the page by using the file browse.

    Would really appreciate help with that basically, I don't want to perform a full page refresh, because it currently operates.

    It has to do with the fact that this report is the question about a BLOB column, which is a link to the uploaded file?

    Thank you.

    Tony.

    Hello

    Check this area of report model have id.
    You should have id = "" #REGION_STATIC_ID # "in the model of the region"

    Make sure you have correctly write the id of the report in JavaScript. JavaScript is case-sensitive

    Kind regards
    Jari

  • help on a pl sql script

    Hi all!

    I'm new to pl sql.

    Can sb help me on how to do this:

    I have a table where I want to find the max (value) per month for the cod of the CCA.

    So that's how my table is:

    InstanceId date value acc_cod

    20/02/2013 1, 2

    21/02/2013 2, 3 has

    3                     23/02/2013     6                  b

    16/09/2014 4, 12 b

    Oh... I did not notice that... Try the below

    SELECT instanceid,

    acc_cod,

    DATE_,

    value

    Of

    (SELECT instanceid,
    acc_cod,

    DATE_,

    value,

    Max (InstanceId) OVER (PARTITION BY acc_cod, TO_CHAR (date_, 'MONYYYY')) mx_val

    FROM table_name)

    WHERE mx_val = instanceid;

    (GOLD)

    SELECT instanceid,

    acc_cod,

    DATE_,

    value

    Of

    (SELECT instanceid,

    DATE_,

    acc_cod,

    value,

    ROW_NUMBER() over (PARTITION BY acc_cod, TO_CHAR(date_,'MONYYYY') ORDER BY DESC instanceid) rn

    FROM table_name)

    WHERE rn = 1;

  • Help with anonymus pl/sql layout using javascript

    Hi people.

    I want to display records on a region (using apex 4.2), this anonymous pl/sql script below shows 3 records in database, but the layout only shows me the first album with its data, the other 2 files, only show me the labels.
    I checked this same query creating a report and it shows the 3 files correctly.
    I guess I'm doing something wrong with this javascript routine or certainly miss something,
    in this link you can see the layout I get. (http://sdrv.ms/Xrv0J8).

    Another is the little help I need to display in a line for each record. in fact, I'm getting a line for each label and a line for each data record. I have read and learned something is/div, but I don't know how to change it to get the desired results, any suggestion is welcome.

    Thanks in advance for any help.



    I am completely new in apex and java script, but I have several years of experience in pl/sql.

    -------


    The Script:

    Begin
    Declare
    Anyth cursor is
    Select the item,
    To_char (delivery, ' month DD, YYYY hh24:mi:ss ") delivery.
    Current_date
    Of pending_items;
    Begin
    For a loop Anyth
    Begin
    Sys.Htp.P ("< script type =" text/javascript"> '");
    Sys.Htp.P ('function cdtd() {'});
    Sys.Htp.P ("var Christmas = new Date (" ' | ') ") a.Delivery | '")');
    Sys.Htp.P ("var now = new Date();'");
    Sys.Htp.P ("var timeDiff = xmas.getTime () - now.getTime ();'");
    Sys.Htp.P (' if (timeDiff < = 0) {'});
    Sys.Htp.P ('clearTimeout() (timer)');
    -Sys.Htp.P ("document.write ("of the text here.")");
    Sys.Htp.P (' / / execute all necessary code to the completion of the countdown here ');
    Sys.Htp.P ('} ');
    Sys.Htp.P (' var seconds = Math.floor(timeDiff / 1000);) ") ;
    Sys.Htp.P ("var minutes = Math.floor(seconds / 60) ;");
    Sys.Htp.P (' varhour = Math.floor(minutes / 60);) ") ;
    Sys.Htp.P ("days var Math.floor(hours / 24) = ;"); ")
    Sys.Htp.P (' hours = 24 ;'); %)
    Sys.Htp.P (' minutes % = 60 ;');)
    Sys.Htp.P (' seconds % = 60 ;');)
    Sys.Htp.P (' document.getElementById("daysBox").innerHTML = days ;');)
    Sys.Htp.P (' document.getElementById("hoursBox").innerHTML = hours;) ") ;
    Sys.Htp.P (' document.getElementById("minsBox").innerHTML = minutes ;');)
    Sys.Htp.P (' ;'); seconds = document.getElementById("secsBox").innerHTML)
    Sys.Htp.P (' timer var = setTimeout ("cdtd ()", 1000);');
    Sys.Htp.P ('} ');
    Sys.Htp.P ("< /script >");
    Sys.Htp.P ("days");
    Sys.Htp.P ("< div id ="daysBox"> < / div > '");
    Sys.Htp.P ("hours");
    Sys.Htp.P ("< div id ="hoursBox"> < / div > '");
    Sys.Htp.P ('minute');
    Sys.Htp.P ("< div id ="minsBox"> < / div > '");
    Sys.Htp.P ("seconds");
    Sys.Htp.P ("< div id ="secsBox"> < / div > '");
    Sys.Htp.P ("< script type =" text/javascript"> '");
    Sys.Htp.P ('cdtd() < /script > ');
    End;
    End loop;
    End;
    End;

    For now, let's focus on delivery dates and the javascript.
    Why you would put your javascript in htp.p called in a plsql region is beyond me. When you edit the page there is a region of javascript where you can put global variables and functions, a great spot for it then and much easier to manage than that.
    Now, it is also clear that your query on pending items will return multiple records. Thus, using a report would serve you well in this case. However, using code like this:

    document.getElementById("daysBox").innerHTML = days;
    document.getElementById("hoursBox").innerHTML = hours;
    document.getElementById("minsBox").innerHTML = minutes;
    document.getElementById("secsBox").innerHTML = seconds;
    

    you won't have to. getElementById is supposed to return an element identified by a code. If you have a report that contains multiple lines and elements on each line with the same ID, you're doing something wrong. You should be the date of delivery by rank, and I suppose that you put your code with htp.p because you don't know how to deal with this and passing the procedure of javascript.
    But would it not more oppurtune for you simply create a report with a sql source when you calculate each part of the date and then refresh this region with a certain interval. If you would be refreshed every 5 minutes, not who is more fast enough to keep track of things? Remember, refreshing a region will execute the SQL again.
    It is not that you cannot make a report multi-record with a countdown by rank, but are you sufficiently comfortable with javascript and jquery to encode and maintain that against leverage plsql and dynamic actions (there is even an action timer plugin supplied by oracle dynamic)?

  • Need help in writing the SQL CASE or DECODE statement

    Hi experts,

    I need to write a SQL select order_num, cntry_cde, prod_id and Qty by joining order_num on PROD_ORDER and PROD_ORDER_TXT.

    Here is my sample data

    PROD ORDER_
    order_num Prod_id Qty cntry_cde
    100 US A1 5
    101 US 10 A2
    102 IN A3 4
    103 TO THE A4 9
    104. IN A5 3

    PROD ORDER_TXT_
    cntry_cde Prod_id order_num
    100 US A1
    101 US A2
    102 NZ A3
    103 TO THE A4
    A5 104

    Here's the requirement,

    (1) if the cntry_cde in PROD_ORDER is the same as cntry_cde in PROD_ORDER_TXT then select PROD_ORDER.cntry_cde (orders 100, 101, 103)
    (2) if they are different, choose PROD_ORDER_TXT (order 102, to THE NZ <>) country code
    (3) if they are different and PROD_ORDER_TXT.cntry_cde is null, I can't use it like cntry_cde in my report (order 104). It happenend just because of bad data to the source.
    I can't avoid it. Then just use the cntry_cde of PROD_ORDER

    Expected results
    100 US A1 5
    101 US 10 A2
    102 NZ A3 4 - changed in NZ
    103 TO THE A4 9
    104. IN A5 3 - IN retained as PROD_ORDER_TXT.cntry_cde is null


    instructions for creation and insertion of sample table are lower than

    create the table prod_order
    (number of order_num,
    cntry_cde CHAR (2),
    prod_id VARCHAR2 (6).
    number of quantity)

    create the table prod_order_txt
    (number of order_num,
    cntry_cde CHAR (2),
    prod_id VARCHAR2 (6))

    insert into prod_order values (100, 'WE', 'A1', 5);
    insert into prod_order values (101, 'WE', 'A2', 1);
    insert into prod_order values (102, ' to THE ', 'A3', 4);
    insert into prod_order values (103, ' to THE ', 'A4', 9);
    insert into prod_order values (104, 'IN', 'A5', 3);



    insert into prod_order_txt values (100, 'WE', 'A1');
    insert into prod_order_txt values (101, 'WE', 'A2');
    insert into prod_order_txt values (102, 'NZ', 'A3');
    insert into prod_order_txt values (103, ' to THE ', 'A4');
    insert into prod_order_txt values (104, 'A5', NULL);

    commit;

    Thank you for your help in advance

    Published by: manon March 28, 2012 13:39
  • (Editable report) SQL query with line selector

    I used this code to get the update of the records in a query SQL (editable report).
    Updates a value in a selection box.

    because me in 1... apex_application.g_f01. Count
    loop
    UPDATE CONTRACTS
    SET LOAD_FLAG =: P8_SELECT
    WHERE ID = apex_application.g_f01 (i); -i'the checked the file 'primary key '.
    end loop;

    Here's my dilemma.
    Line selector seems to be in a fixed position.
    By linking the line for identification number selector (1, 2, 3, etc.)
    Sort by ID (1, 2, 3, etc.)
    It works perfectly, as long as the ID is sorted in order. < <
    If it is sorted by another field with say ID 29 now in the 1st row, by checking the box and update, you update ID #1 located elsewhere on the page.
    Any ideas how to make the line selector literally equal to the line, it is displayed in?
    Thank you
    Bob

    I think I have an idea of what is wrong and, eventually, how to fix it. Try this:

    make your field primary key (NO ROWID!) in a column in a table column, either through the "wizard" (i.e. through the report attributes screen), or using the APEX_ITEM api (as described by Vee). I often have my primary key as a hidden; If you really need to see it, you can use "DISPLAY_AND_SAVE".

    So if your primary key 'ID' colum is now in the 2nd table as a table (i.e. f02 - adjust accordingly!), your PL/SQL process should look like this:

    for i in 1 .. apex_application.g_f01.count
    loop
       UPDATE CONTRACTS
          SET LOAD_FLAG = :P8_SELECT
        where ID = apex_application.g_f02(apex_application.g_f01(i)); 
    
    end loop;
    

    It of a little confusing at first but it it makes sense when you train how tabular tables work with check boxes. The length of this array represents only what is verified - so if you have 3 values checked, the cardinality of the table in a particular table 3. On the other hand, your other tabular berries (containing the 'normal' values) has a cardinality of the count of all the visible lines.

    In this case, the record selector (F01) contains the ID of the relevant line in your report - so passing this value in the array index 2 (F02) should give you the correct primary key for that particular line value. If you subsequently order the report by another field, it should work again.

    I should add that Vee method will work well - the difference is that, instead of organizing the rowid, f01 contains the actual key value. Hope this helps

    Published by: Joel_C on March 21, 2011 11:50

  • Classic report SQL question.

    Hello

    Can I use Snap on command in a classic report using SQL? If so, how?

    I use APEX 3.2.1 with Oracle database 10g.

    Thank you
    Mary

    Published by: Gabriel on July 23, 2010 11:20

    Hello Mary,.

    WE BREAK is a SQL * more order thus is not allowed in the SQL of a usual report.

    To do this is to use the Break formatting attributes report section. He limited to the break at first, & second or first, second & third columns rows retrieved, but it may be enough for what you're trying to accomplish.

    Hope this helps,
    John

Maybe you are looking for