Hierarchical Query Sort help needed in 9i (9.2.0.6)

Hello all, hope you guys are far away from IKE (it hit us pretty bad last weekend), anyway come to point
My requirement is data sorted by name is such a way after parent show its childs (if exists) i.e first sort parents and then by childs within parants
I am expecting this
1     BBQU-1
2     BBQU-1 Sub event 1
3     BBQU-1 Sub event 2
10     BBQU-1 Sub event 3
6     BBQU-1 Birthday
5     BBQU-1 Advance
7     BBQU-2
4     BBQU-2 Sub event
from
1     BBQU-1     
5     BBQU-1 Advance     
2     BBQU-1 Sub event 1     1
3     BBQU-1 Sub event 2     1
10     BBQU-1 Sub event 3     1
6     BBQU-1 Birthday     
7     BBQU-2     
4     BBQU-2 Sub event     7
Here is the script for table and data.
create table no_more_ike (event_id number, event_name varchar2(30), subevent_id number);
insert into no_more_ike values (1, 'BBQU-1', null);
insert into no_more_ike values (5, 'BBQU-1 Advance', null);
insert into no_more_ike values (2, 'BBQU-1 Sub event 1', 1);
insert into no_more_ike values (3, 'BBQU-1 Sub event 2', 1);
insert into no_more_ike values (10, 'BBQU-1 Sub event 3', 1);
insert into no_more_ike values (6, 'BBQU-1 Birthday', null);
insert into no_more_ike values (7, 'BBQU-2', null);
insert into no_more_ike values (4, 'BBQU-2 Sub event', 7);
commit;
Thanks a lot

Is this OK?
select
   event_id,
   event_name,
   subevent_id
from no_more_ike
start with SUBEVENT_ID is null
connect by prior EVENT_ID = SUBEVENT_ID
order by decode(subevent_id, null, event_id, subevent_id) asc;

Similar Messages

  • PROBLEM WITH HIERARCHICAL QUERY - PLEASE HELP

    I have got three tables :
    CREATE TABLE FIRM
    (FID INTEGER NOT NULL PRIMARY KEY,
    FNAME VARCHAR(40),
    FTYPE VARCHAR(3),
    MASTERID INTEGER );
    CREATE TABLE FACULTY
    (FAID INTEGER NOT NULL PRIMARY KEY,
    FANAME VARCHAR(40),
    FATYPE VARCHAR(3),
    MASTERID INTEGER );
    CREATE TABLE EMPLOYEE
         (EID INTEGER NOT NULL PRIMARY KEY,
    ENAME VARCHAR(20),
    ESURNAME VARCHAR(20),
         EJOB VARCHAR(3),
         MASTERID INTEGER );
    This is a hierarchical tree(or is ment to be, I,m complete rookie ) . Firm can be the root or can be slave to another firm. Faculty can be slave to firm, or to another faculty. Employee can be slave to faculty or to another employee(e.g. boss). This connections are specified by MASTERIDs.
    I need to write a procedure, which parameter would be node ID. It is meant to create a VIEW from this node as if it was a root (view of a subtree).
    I tried CONNECT BY clause but it works only on one table at a time and I have here three tables.
    I completely don,t know how to write it. Please help.

    create view hierarchy as
    select id, master_id, name from table1
    union all
    select id, master_id, name from table2
    union all
    select id, master_id, name from table3
    Then do your connect by query against hierarchy.
    It will not work in 8i (connect by on views not allowed), so you will need to materialize the view.
    Kirill

  • Performance issue on query. Help needed.

    This is mainly a performance issue. I hope someone can help me on this.
    Basically I have four tables Master (150000 records), Child1 (100000+ records), Child2 (50 million records !), Child 3 (10000+ records)
    (please pardon the aliases).
    Now every record in master has more than one corresponding record in each of the child tables (one to many).
    Also there may not be any record in any or all of the tables for a particular master record.
    Now, I need to fetch the max of last_updated_date for every master record in each of the 3 child tables and then find the maximum of
    the three last_active_dates obtained from the 3 tables.
    eg: for Master ID 100, I need to query Child1 for all the records of Master ID 100 and get the max last_updated_date.
    Same for the other 2 tables and then get the maximum of these three values.
    (I also need to take care of cases where no record may be found in a child table for a Master ID)
    Writing a procedure that uses cursors that fetches the value from each of the child table hits performance
    badly. And thing is I need to find out the last_updated_date for every Master record (all 150000 of them). It'll probably take days to do this.
    SELECT MAX (C1.LAST_UPDATED_DATE)
    ,MAX (C2.LAST_UPDATED_DATE)
    ,MAX (C3.LAST_UPDATED_DATE)
    FROM CHILD1 C1
    ,CHILD2 C2
    ,CHILD3 C3
    WHERE C1.MASTER_ID = 100
    OR C2.MASTER_ID = 100
    OR C3.MASTER_ID = 100
    I tried the above but I got a temp tablespace error. I don't think the query is good enough at all.
    (The OR clause is to take care of no records in any child table. If there's an AND, then the join and hence select will
    fail even if there is no record in one child table but valid values in the other 2 tables).
    Thanks a lot.
    Edited by: user773489 on Dec 16, 2008 11:49 AM

    Not sure I understand the problem. The max you are getting from the above is already the greatest out of the three - that's why we do the UNION ALL.
    Here's sample code without output, maybe this will clear it up:
    with a as (
    select 10 MASTER_ID, to_date('12/15/2008', 'MM/DD/YYYY') LAST_DTE from dual UNION ALL
    select 20 MASTER_ID, to_date('12/01/2008', 'MM/DD/YYYY') LAST_DTE from dual UNION ALL
    select 30 MASTER_ID, to_date('12/02/2008', 'MM/DD/YYYY') LAST_DTE from dual
    b as (
    select 10 MASTER_ID, to_date('12/14/2008', 'MM/DD/YYYY') LAST_DTE from dual UNION ALL
    select 20 MASTER_ID, to_date('12/02/2008', 'MM/DD/YYYY') LAST_DTE from dual UNION ALL
    select 40 MASTER_ID, to_date('11/15/2008', 'MM/DD/YYYY') LAST_DTE from dual
    c as (
    select 10 MASTER_ID, to_date('12/07/2008', 'MM/DD/YYYY') LAST_DTE from dual UNION ALL
    select 30 MASTER_ID, to_date('11/29/2008', 'MM/DD/YYYY') LAST_DTE from dual UNION ALL
    select 40 MASTER_ID, to_date('12/13/2008', 'MM/DD/YYYY') LAST_DTE from dual
    select MASTER_ID, MAX(LAST_DTE)
    FROM
    (select MASTER_ID, LAST_DTE from a UNION ALL
    select MASTER_ID, LAST_DTE from b UNION ALL
    select MASTER_ID, LAST_DTE from c)
    group by MASTER_ID;
    MASTER_ID              MAX(LAST_DTE)            
    30                     02-DEC-08                
    40                     13-DEC-08                
    20                     02-DEC-08                
    10                     15-DEC-08                
    4 rows selectedEdited by: tk-7381344 on Dec 16, 2008 12:38 PM

  • In car calls query. Help needed

    I'm doing this on behalf of my flat mate who has a Curve 8520. I've just brought her a 3.5mm jack cable to link her phone to her headunit to play her tunes and it worked perfectly. While we were sorted this out we wondered how easy it was to use her new setup up as an in-car call kit. We called her phone to see what would happen and to see if the call would automatically use the car speakers for the call instead of the phone. Unfortunately the call came through the phone and not the speakers. We then went to turn on the speakerphone but as you can imagine isn't really  the method we wanted to employ. Does anyone know of any setting on the phone so that the calls can come straight through speakers or any cheap products that would allow her to do this?
    Any help would be gratefully recieved

    I'm doing this on behalf of my flat mate who has a Curve 8520. I've just brought her a 3.5mm jack cable to link her phone to her headunit to play her tunes and it worked perfectly. While we were sorted this out we wondered how easy it was to use her new setup up as an in-car call kit. We called her phone to see what would happen and to see if the call would automatically use the car speakers for the call instead of the phone. Unfortunately the call came through the phone and not the speakers. We then went to turn on the speakerphone but as you can imagine isn't really  the method we wanted to employ. Does anyone know of any setting on the phone so that the calls can come straight through speakers or any cheap products that would allow her to do this?
    Any help would be gratefully recieved

  • Query urgent help need

    hi friends,
    Could u please help me how to do this
    tables : knb1,     "customer master (companycode)
             kna1,     "genaral data in customer master
             knvp.     "customer master partener functions
            zvarv.    "Program Hard Coded Values support table
           TYPE-POOLS DEFINATION
    type-pools : slis.
           TYPES DECLARATION
          Customer Master Company code Data
    types : begin of t_knb1,
              kunnr like knb1-kunnr,
              akont like knb1-akont,
            end of t_knb1.
    data : i_knb1 type t_knb1 occurs 0 with header line .
          Customer Master
    types : begin of t_kna1,
              kunnr like kna1-kunnr,
              name1 like kna1-name1,
              stras like kna1-stras,
              ort01 like kna1-ort01,
              stcd1 like kna1-stcd1,
              pstlz like kna1-pstlz,
            end of t_kna1.
    data  : i_kna1 type t_kna1 occurs 0 with header line.
          Customer Partner Functions
    types : begin of t_knvp,
              kunnr like knvp-kunnr,
              vkorg like knvp-vkorg,
              parvw like knvp-parvw,
              kunn2 like knvp-kunn2,
            end of t_knvp.
    data : i_knvp type t_knvp occurs 0 with header line.
          Output data
    types : begin of t_output,
              recordtype      type c,
              soldtocust(10)  type c,
              payer(10)       type c,
              sequence(5)     type n,
              custname(35)    type c,
              custaddress(35) type c,
              custcity(35)    type c,
              taxid(16)       type c,
              postalcode(5)   type c,
              branch          type c,
              delivery(3)     type c,
            end of t_output.
    data : i_output type t_output occurs 0 with header line.
          ZVARV Table
    *types : begin of t_zvarv,
             zobject1 like zvarv-zobject1,
             zobject2 like zvarv-zobject2,
             zseqnumb like zvarv-zseqnumb,
             zobjval  like zvarv-zobjval,
           end of t_zvarv.
    *data : i_zvarv  type  t_zvarv occurs 0 with header line.
          Error messages and total records
    types : begin of t_error_log,
              message(200) type c,
            end of t_error_log.
    data : i_error_log type t_error_log occurs 0 with header line.
         Field catalog
    data : t_fieldcat_tab type slis_t_fieldcat_alv with header line.
    Variables
    data : "v_aufsd like i_zvarv-zobjval,   "Central order block for cust
           v_knb1 type t_knb1,             "Customer master company code
           v_kna1 type t_kna1,             "Customer master
           v_knvp type t_knvp,             "Customer masterpartenerfunctions
           v_output type t_output,         "Output data
           v_error_log type t_error_log,   "Error data
           v_sequence(5) type n,           "Total records
           v_line type i,                  "Message
           v_count type i,                 "Counter for KNA1 records
           v_count1 type i,                "Counter for KNVP records
           v_result(100) type c,           "Totals for KNA1
           v_result1(100) type c,          "Totals for KNVP
           v_vkorg like knvp-vkorg.        "Message for Validation
    Constants
    data : c_program(30) type c value 'ZSDI0215', " Program Name
           c_parvw_rg    like  knvp-parvw value 'RG', "Partner type
           c_aufsd(2)    type c value 'CD'.    "Central order block for Cust
                       Selection-screen
    selection-screen begin of block b1 with frame title text-001.
    parameters       : p_vkorg like knvp-vkorg obligatory. "Sales Org
    select-options   : s_akont for knb1-akont obligatory default
                           '0001050100'.      "Reconciliation Account
    selection-screen end of block b1.
    selection-screen begin of block b2 with frame title text-002.
    parameters       : p_alv as checkbox,
                       p_df as checkbox.
    selection-screen end of block b2.
    selection-screen begin of block b3 with frame title text-003.
    parameters : p_lfile like  filetextci-fileintern
                   default 'Z_IO01989_CUSTOMER_MASTER_DATA', " Logical file
                 p_pfile like  rfpdo-rfbifile.               " Physical File
    selection-screen end of block b3.
         At selection-screen
    at selection-screen on p_vkorg.
    Validation of Sales Organization
      select single vkorg
        into v_vkorg
        from tvko
        where vkorg = p_vkorg.
      if v_vkorg is initial.
         message e045 with text-030.
      endif.
         Start-of-selection
    start-of-selection.
    Fetch data
      perform get_data.
    Processing the data
      perform process_data.
        End-of-Selection
    end-of-selection.
      if p_alv eq 'X'.
    Field catalog
        perform f_prepare_fieldcat.
    Disply  alv report
        perform f_display_report.
    Disply error log
        perform f_error_log.
    elseif p_df eq 'x'.
    Disply logical file & physical file
        perform f_logical_file.
        perform f_physical_file.
      else.
    Display the list
        perform f_list_display.
    Disply logical file & physical file
       perform f_logical_file.
       perform f_physical_file.
      endif.
         Form  get_data
         Fetch data and store in internal tables
    form get_data .
    Get zvarv data.
      perform get_zvarv.
    Get knb1 data
      perform get_knb1.
    Get kna1 data
      perform get_kna1.
    Get knvp data
      perform get_knvp.
    endform.                   " get_data
         form  get_zvarv
         zvarv data
    form get_zvarv .
    Fetch data from zvarv.
    select zobject1 zobject2 zseqnumb zobjval
       from zvarv
       into table i_zvarv
      where zobject1 eq c_program.
    sort i_zvarv by zobject2.
    endform.                    " get_zvarv
         form  get_knb1
         Get KNB1 data
    form get_knb1 .
    Fetch data from knb1.
      select kunnr akont
        from knb1
        into table i_knb1
       where akont in s_akont.
      describe table i_knb1 lines v_line.
    endform.                                                    " get_knb1
          Form  get_kna1
          Get KNB1 data
    form get_kna1 .
    Fetch data from kna1.
      select kunnr name1 stras ort01 stcd1 pstlz
        from kna1
        into table i_kna1
        for all entries in i_knb1
       where kunnr = i_knb1-kunnr and
       aufsd ne 'cd'."v_aufsd.
    endform.                                                    " get_kna1
          Form  get_knvp
          Get KNVP data
    form get_knvp .
    Fetch data from knvp
      select kunnr parvw kunn2 vkorg
        from knvp
        into table i_knvp
        for all entries in i_knb1
       where kunnr = i_knb1-kunnr
       and vkorg = p_vkorg
       and parvw = c_parvw_rg.
    endform.                    " get_knvp
          Form  process_data
          Processing output data
    form process_data .
    Get AUFSD value from ZVARV
      perform zvarv_read.
    loop at i_knb1.
        read table i_kna1 with key kunnr = i_knb1-kunnr.
        if sy-subrc ne 0.
         concatenate: 'in kna1 no record found for Customer number'
                       i_knb1-kunnr
                       into v_result separated by space.
          move v_result to v_error_log-message.
          append v_error_log to i_error_log.
          v_count = v_count + 1.
        else.
        move :  i_kna1-name1 to i_output-custname,
                i_kna1-stras to i_output-custaddress,
                i_kna1-ort01 to i_output-custcity,
                i_kna1-stcd1 to i_output-taxid,
                i_kna1-pstlz to i_output-postalcode.
    append i_output
    endif.
       loop at i_knvp where kunnr eq knb1-kunnr.
        read table i_knvp  with key kunnr = i_knb1-kunnr.
        if sy-subrc <> 0.
          concatenate : 'in knvp no record found for customer number'
                         v_knb1-kunnr
                         into v_result1 separated by space.
          move v_result1 to v_error_log-message.
          append v_error_log to i_error_log.
          v_count1 = v_count1 + 1.
         else.
      Move the knvp data to output
         move : i_knvp-kunnr to i_output-soldtocust,
                i_knvp-kunn2 to i_output-payer.
    append i_output
    endif.
         endloop.
        v_sequence = v_sequence + 1.
    Move non table related data to output
        move : 'C'          to i_output-recordtype,
                v_sequence  to i_output-sequence,
               '1'          to i_output-branch,
               'ABC'        to i_output-delivery.
    append i_output.
    endif.
    endloop.
    when i execute this one same data is displaying two times
    for example total records is two
    first record displaying two times and second one is displaying two times
    please tell me how to do
    regards
    harshavi

    Hi ,
    first check all APPEND stmts ?. In any report u have to maintain one BASE internal table .
    If u are working on KUNNR level , So maintain one final Internal table with all KUNNRS then Process all the data for final output.
    regards
    prabhu

  • Radix sort help needed

    Can someone please help me with this radix sort on a dictionary (linkedList from the java utils). I am trying to pass the linkedList into an array which the java apis say that you can do with the to.Array() method but I am getting the noninformative cannot resolve symbol. Like the theory here is that one I should be able to pass a linkedList into an array and two, that I should be able to sort the list by calling the substrings(1,MAX_LENGTH) and then do a minus one on the length for the recursive call. However, this is giving me fits at this point and I don't know if I am totally off track and this will never work or if I am just not thinking it through clearly.
    Any help at all would be appreciated greatly...
    import java.util.*;
    public class radixSort
      //  radix sort using linked lists, where radixSort is not
      //  a method of the LinkeList class.
       public void radixSort(LinkedList listA)
       //*******************this is the line that's giving me fits***********************/
       java.util.LinkedList[] objArray = listA.toArray();
       final int MAX_LENGTH  =  8;    //  Strings are no more than 8 characters
       final int RADIX_SIZE = 26;    //  Alphabet has 26 letters
       // Use an array of 26 ArrayLists to groups the elements of the array
       createQueue[] groups = new createQueue[RADIX_SIZE];
       for (int x = 0; x < MAX_LENGTH; x++)
                 for (int i; i < MAX_LENGTH; i++)
                 groups = new createQueue();
              for (int position=MAX_LENGTH; position < 0; position--)
    for (int scan=0; scan < MAX_LENGTH; scan++)
    //ListIterator iter1 = listA.listIterator();
    String temp = String.valueOf (listA[scan]);
    String letter = temp.substring(0, position);
    groups[letter].enqueue ((listA[scan]));
    // gather numbers back into list
    int num = 0;
    for(int d=0; d<MAX_LENGTH; d++)
    while (!(groups[d].isEmpty()))
    numObj = groups[d].dequeue();
    listA[num] = numObj.intValue();
    num++;
    //****************************Here is the createQueue class...***********************/
    public class createQueue
    * Construct the queue.
    public createQueue( )
    front = back = null;
    * Test if the queue is logically empty.
    * @return true if empty, false otherwise.
    public boolean isEmpty( )
    return front == null;
    * Insert a new item into the queue.
    * @param x the item to insert.
    public void enqueue( Object x )
    if( isEmpty( ) ) // Make queue of one element
    back = front = new ListNode( x );
    else // Regular case
    back = back.next = new ListNode( x );
    * Return and remove the least recently inserted item
    * from the queue.
    public Object dequeue( )
    if( isEmpty( ) )
    //throw new UnderflowException( "ListQueue dequeue" );
              System.out.println("No elements");
    else;
    Object returnValue = front;
    front = front.next;
    return returnValue;
    * Get the least recently inserted item in the queue.
    * Does not alter the queue.
    public Object getFront( )
    if( isEmpty( ) )
    System.out.println("No elements");
    else;
    return front;
    * Make the queue logically empty.
    public void makeEmpty( )
    front = null;
    back = null;
    private ListNode front;
    private ListNode back;
    private void printans()
         if (isEmpty())
         System.out.println("No elements");
         else
         while (back != front)
         System.out.println (front);
         //front++;

    java.util.LinkedList[] objArray = listA.toArray();Impossible! You are going to convert a LinkedList to an array of LinkedList. It's impossible! Or, sheer nonsense, if ever possible.

  • URGENT SORT HELP NEEDED

    Hey everyone...
    This is VERY time critical....
    Could someone give me a method that uses an Insertion Sort to sort an array of Strings??
    Please help!!!
    Thanks!!
    Lardiop

    Object[] arr = new Object[size];
    Object temp1;
    for(int i=2; i <= arr.length; i++) {
      for(int j=i-1; j > 0; j--) {
        if(arr[j].compareTo(arr[j - 1]) < 0) {
          temp1 = arr[j];
          arr[j] = arr[j - 1];
          arr[j - 1] = temp1;
    }

  • SQL query urgent helps needed!!!

    Hi all,
    I got the following query :-
    SELECT RH.REQUEST_NUMBER,     
         MSIK.CONCATENATED_SEGMENTS,
    MSIK.DESCRIPTION,
         RL.FROM_SUBINVENTORY_CODE,
         RL.UOM_CODE,
         RL.QUANTITY,
    PP.FULL_NAME     ,
         M.TRANSACTION_QUANTITY
    FROM     MTL_TXN_REQUEST_HEADERS RH,
    MTL_TXN_REQUEST_LINES RL,
         MTL_SYSTEM_ITEMS_KFV MSIK,
    FND_USER FU,
    PER_PEOPLE_V7 PP,
              ( SELECT MSIK2.CONCATENATED_SEGMENTS, MOQ.SUBINVENTORY_CODE, SUM(MOQ.TRANSACTION_QUANTITY)
              FROM MTL_ONHAND_QUANTITIES MOQ, MTL_SYSTEM_ITEMS_KFV MSIK2
              WHERE MSIK2.INVENTORY_ITEM_ID = MOQ.INVENTORY_ITEM_ID
              AND MSIK2.ORGANIZATION_ID = 8
              AND MOQ.SUBINVENTORY_CODE LIKE 'ST%'
              GROUP BY MSIK2.CONCATENATED_SEGMENTS, MOQ.SUBINVENTORY_CODE) M
    WHERE     
    RH.HEADER_STATUS IN(3,7,8)
    AND RH.MOVE_ORDER_TYPE IN(1,2)
    and rh.header_id = rl.header_id
    AND MSIK.INVENTORY_ITEM_ID = RL.INVENTORY_ITEM_ID
    AND MSIK.ORGANIZATION_ID = 8
    AND RL.FROM_SUBINVENTORY_CODE LIKE 'ST%'
    AND RH.CREATED_BY = FU.USER_ID
    AND FU.EMPLOYEE_ID = PP.PERSON_ID
    However, when I try to run I got the invalid column for m.transaction_quantity ??? why? does it b'cos of the group sum that I used ?
    My intention of this query to display the sum of total qty from the mtl_onhand_quantities table.
    Please helps.
    Thanks.
    Rgds
    Lim

    sorry if its too late.....
    my guess is alias the SUM(MOQ.TRANSACTION_QUANTITY) in the sub-query table (M) as TRANSACTION_QUANTITY.
    -------- code snippet---------
    FND_USER FU,
    PER_PEOPLE_V7 PP,
    ( SELECT MSIK2.CONCATENATED_SEGMENTS, MOQ.SUBINVENTORY_CODE,
    SUM(MOQ.TRANSACTION_QUANTITY) TRANSACTION_QUANTITY <------------------------------------This is important
    FROM MTL_ONHAND_QUANTITIES MOQ, MTL_SYSTEM_ITEMS_KFV MSIK2
    WHERE MSIK2.INVENTORY_ITEM_ID = MOQ.INVENTORY_ITEM_ID
    AND MSIK2.ORGANIZATION_ID = 8
    AND MOQ.SUBINVENTORY_CODE LIKE 'ST%'
    GROUP BY MSIK2.CONCATENATED_SEGMENTS, MOQ.SUBINVENTORY_CODE) M
    WHERE
    RH.HEADER_STATUS IN(3,7,8)
    AND RH.MOVE_ORDER_TYPE IN(1,2)
    --------------code snippet ends------------------------
    hope this helps,

  • Query Tuning-Help Needed

    Hi ,
    11.2.0.1
    AIX 6.1
    I have following query which is executed from Application,the query comes back within 2 secs for not so common last_name combined with gender but it is taking longer time for common last_names like 'BROWN' or 'JONES' or 'SMITH' with gender_id .
    select customerin0_.ROW_NUMBER as ROW1_22596_, customerin0_.ADDRESS_ID as
      ADDRESS2_22596_, customerin0_.addressTypeId as addressT3_22596_,
      customerin0_.city as city22596_, customerin0_.CONTACT_DETAILS_CODE_ID as
      CONTACT5_22596_, customerin0_.county as county22596_, customerin0_.countyID
      as countyID22596_, customerin0_.dob as dob22596_, customerin0_.eyecolor as
      eyecolor22596_, customerin0_.eyecolorid as eyecolorid22596_,
      customerin0_.FIRST_NAME as FIRST11_22596_, customerin0_.gender as
      gender22596_, customerin0_.genderid as genderid22596_,
      customerin0_.ID_NUMBER as ID14_22596_, customerin0_.JURISDICTION_CODE as
      JURISDI15_22596_, customerin0_.LAST_NAME as LAST16_22596_,
      customerin0_.LEGAL_ENTITY_ID as LEGAL17_22596_,
      customerin0_.LEGAL_ENTITY_NUMBER as LEGAL18_22596_,
      customerin0_.LEGAL_ENTITY_TYPE as LEGAL19_22596_, customerin0_.MIDDLE_NAME
      as MIDDLE20_22596_, customerin0_.STREET_ADDRESS_1 as STREET21_22596_,
      customerin0_.suffix_value as suffix22_22596_, customerin0_.ZIP_CODE as
      ZIP23_22596_, customerin0_.ZIP_PLUS_4 as ZIP24_22596_
    from
    CUSTOMER_IND_SEARCH_VIEW customerin0_ where (customerin0_.LAST_NAME like :1)
      and customerin0_.genderid=:2 and rownum<=200
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        0      0.00       0.00          0          0          0           0
    Execute      0      0.00       0.00          0          0          0           0
    Fetch       18      1.88     123.53       8245      12403          0         179
    total       18      1.88     123.53       8245      12403          0         179
    Misses in library cache during parse: 0
    Parsing user id: 135  (???)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      ges message buffer allocation                 259        0.00          0.00
      gc cr grant 2-way                             259        0.00          0.08
      db file sequential read                     10126        1.40        148.07
      SQL*Net message from client                    19        0.02          0.10
      SQL*Net message to client                      18        0.00          0.00
    ********************************************************************************Was not able to generate plan out of tkrprof ,captured it from OEM.
      10 |     NESTED LOOPS                  |                              |   805 | 73255 |  3477   (1)| 00:00:42 |
    |  11 |      NESTED LOOPS                 |                              |   805 | 51520 |  1866   (1)| 00:00:23 |
    |  12 |       NESTED LOOPS                |                              |   805 | 33005 |   254   (0)| 00:00:04 |
    |* 13 |        TABLE ACCESS BY INDEX ROWID| REF_CONTACT_DETAILS          |     1 |    10 |     1   (0)| 00:00:01 |
    |* 14 |         INDEX UNIQUE SCAN         | XAK1_REF_CD_VALUE            |     1 |       |     0   (0)|          |
    |  15 |        TABLE ACCESS BY INDEX ROWID| PERSON_PROFILE_NAMES         |   805 | 24955 |   253   (0)| 00:00:04 |
    |* 16 |         INDEX RANGE SCAN          | IDX$$_D7D50001               |   805 |       |     4   (0)| 00:00:01 |
    |* 17 |       TABLE ACCESS BY INDEX ROWID | PERSON_PROFILE               |     1 |    23 |     2   (0)| 00:00:01 |
    |* 18 |        INDEX UNIQUE SCAN          | XPK_PERSON_PROFILE           |     1 |       |     1   (0)| 00:00:01 |
    |* 19 |      TABLE ACCESS BY INDEX ROWID  | LEGAL_ENTITY                 |     1 |    27 |     2   (0)| 00:00:01 |
    |* 20 |       INDEX UNIQUE SCAN           | XPK_LEGAL_ENTITY             |     1 |       |     1   (0)| 00:00:01 |
    |* 21 |     TABLE ACCESS BY INDEX ROWID   | LEGAL_ENTITY_ADDRESSES       |     1 |    81 |     3   (0)| 00:00:01 |
    |* 22 |      INDEX RANGE SCAN             | LENUM_CODE_ID                |     1 |       |     2   (0)| 00:00:01 |
    |* 23 |    TABLE ACCESS BY INDEX ROWID    | LEGAL_ENTITY_IDENTIFICATIONS |     1 |    36 |     3   (0)| 00:00:01 |
    |* 24 |     INDEX RANGE SCAN              | XIF1_LEGAL_ENTITY_ID         |     1 |       |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("REFCOUNTIES"."ID"=:B1)
       4 - access("REFEYECOLORS"."ID"=:B1)
       6 - access("REFGENDER"."ID"=:B1)
       7 - filter(ROWNUM<=200)
      13 - filter("REFCONTACTDETAILS"."MODE_TYPE"=4)
      14 - access("REFCONTACTDETAILS"."VALUE"='PRA')
      16 - access("PERSONPROFILENAMES"."LAST_NAME" LIKE :1 AND "PERSONPROFILENAMES"."IS_DELETED"=0)
           filter(("PERSONPROFILENAMES"."LAST_NAME" LIKE :1 AND "PERSONPROFILENAMES"."IS_DELETED"=0))
      17 - filter("SYS_ALIAS_2"."GENDER_ID"=:2)
      18 - access("SYS_ALIAS_2"."PP_LEGALENTITY_NUMBER"="PERSONPROFILENAMES"."PP_LEGALENTITY_NUMBER")
      19 - filter(("LEGALENTITY"."IS_DELETED"=0 OR "LEGALENTITY"."IS_DELETED"=NULL))
      20 - access("LEGALENTITY"."LEGAL_ENTITY_NUMBER"="SYS_ALIAS_2"."PP_LEGALENTITY_NUMBER")
      21 - filter("LEGALENTITYADDRESSES"."IS_DELETED"=0)
      22 - access("LEGALENTITY"."LEGAL_ENTITY_NUMBER"="LEGALENTITYADDRESSES"."LEGAL_ENTITY_NUMBER" AND
                  "REFCONTACTDETAILS"."ID"="LEGALENTITYADDRESSES"."CONTACT_DETAILS_CODE_ID")
      23 - filter(("LEGAL_ENTITY_ID"."END_DATE">=SYSDATE@! AND "LEGAL_ENTITY_ID"."EFFECTIVE_DATE"<=SYSDATE@!))
      24 - access("LEGAL_ENTITY_ID"."LEGAL_ENTITY_NUMBER"="LEGALENTITY"."LEGAL_ENTITY_NUMBER")
      Please advice ....
    Thanks
    Edited by: Monto on Aug 22, 2012 4:22 AM

    Explain Plan with common name.
    SELECT  customerin0_.ROW_NUMBER AS ROW1_22596_,
             customerin0_.ADDRESS_ID AS ADDRESS2_22596_,
             customerin0_.addressTypeId AS addressT3_22596_,
             customerin0_.city AS city22596_,
             customerin0_.CONTACT_DETAILS_CODE_ID AS CONTACT5_22596_,
             customerin0_.county AS county22596_,
             customerin0_.countyID AS countyID22596_,
             customerin0_.dob AS dob22596_,
             customerin0_.eyecolor AS eyecolor22596_,
             customerin0_.eyecolorid AS eyecolorid22596_,
             customerin0_.FIRST_NAME AS FIRST11_22596_,
             customerin0_.gender AS gender22596_,
             customerin0_.genderid AS genderid22596_,
             customerin0_.ID_NUMBER AS ID14_22596_,
             customerin0_.JURISDICTION_CODE AS JURISDI15_22596_,
             customerin0_.LAST_NAME AS LAST16_22596_,
             customerin0_.LEGAL_ENTITY_ID AS LEGAL17_22596_,
             customerin0_.LEGAL_ENTITY_NUMBER AS LEGAL18_22596_,
             customerin0_.LEGAL_ENTITY_TYPE AS LEGAL19_22596_,
             customerin0_.MIDDLE_NAME AS MIDDLE20_22596_,
             customerin0_.STREET_ADDRESS_1 AS STREET21_22596_,
             customerin0_.suffix_value AS suffix22_22596_,
             customerin0_.ZIP_CODE AS ZIP23_22596_,
             customerin0_.ZIP_PLUS_4 AS ZIP24_22596_
      FROM   xmatapp.CUSTOMER_IND_SEARCH_VIEW customerin0_
    WHERE   (customerin0_.LAST_NAME LIKE 'SMITH%')
             AND customerin0_.genderid = 2
             AND ROWNUM <= 200
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.04       0.05          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch       15      5.05     167.51      14050      20246          0         200
    total       17      5.09     167.56      14050      20246          0         200
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: SYS
    Rows     Row Source Operation
         41  TABLE ACCESS BY INDEX ROWID REF_COUNTIES (cr=58 pr=0 pw=0 time=0 us cost=1 size=12 card=1)
         41   INDEX UNIQUE SCAN XPK_REF_COUNTIES (cr=17 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308432)
          7  TABLE ACCESS BY INDEX ROWID REF_EYE_COLORS (cr=11 pr=0 pw=0 time=0 us cost=1 size=10 card=1)
          7   INDEX UNIQUE SCAN XPK_REF_EYE_COLORS (cr=4 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308404)
          1  TABLE ACCESS BY INDEX ROWID REF_GENDER (cr=2 pr=0 pw=0 time=0 us cost=1 size=9 card=1)
          1   INDEX UNIQUE SCAN XPK_REF_GENDER (cr=1 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308759)
        200  COUNT STOPKEY (cr=20175 pr=14050 pw=0 time=2540633 us)
        200   NESTED LOOPS OUTER (cr=20175 pr=14050 pw=0 time=2540633 us cost=103 size=1248 card=6)
        200    NESTED LOOPS  (cr=19756 pr=13775 pw=0 time=17003952 us cost=80 size=1032 card=6)
        200     NESTED LOOPS  (cr=19304 pr=13586 pw=0 time=14271285 us cost=55 size=1092 card=12)
        200      NESTED LOOPS  (cr=19017 pr=13453 pw=0 time=13593988 us cost=31 size=768 card=12)
       4923       NESTED LOOPS  (cr=4640 pr=4614 pw=0 time=63281900 us cost=7 size=492 card=12)
          1        TABLE ACCESS BY INDEX ROWID REF_CONTACT_DETAILS (cr=2 pr=0 pw=0 time=0 us cost=1 size=10 card=1)
          1         INDEX UNIQUE SCAN XAK1_REF_CD_VALUE (cr=1 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308425)
       4923        TABLE ACCESS BY INDEX ROWID PERSON_PROFILE_NAMES (cr=4638 pr=4614 pw=0 time=63269280 us cost=6 size=372 card=12)
       4923         INDEX RANGE SCAN IDX$$_D7D50001 (cr=30 pr=16 pw=0 time=60326 us cost=2 size=0 card=12)(object id 311149)
        200       TABLE ACCESS BY INDEX ROWID PERSON_PROFILE (cr=14377 pr=8839 pw=0 time=0 us cost=2 size=23 card=1)
       4923        INDEX UNIQUE SCAN XPK_PERSON_PROFILE (cr=9454 pr=4288 pw=0 time=0 us cost=1 size=0 card=1)(object id 308484)
        200      TABLE ACCESS BY INDEX ROWID LEGAL_ENTITY (cr=287 pr=133 pw=0 time=0 us cost=2 size=27 card=1)
        200       INDEX UNIQUE SCAN XPK_LEGAL_ENTITY (cr=225 pr=80 pw=0 time=0 us cost=1 size=0 card=1)(object id 308494)
        200     TABLE ACCESS BY INDEX ROWID LEGAL_ENTITY_ADDRESSES (cr=452 pr=189 pw=0 time=0 us cost=3 size=81 card=1)
        200      INDEX RANGE SCAN LENUM_CODE_ID (cr=281 pr=94 pw=0 time=0 us cost=2 size=0 card=1)(object id 307952)
        200    TABLE ACCESS BY INDEX ROWID LEGAL_ENTITY_IDENTIFICATIONS (cr=419 pr=275 pw=0 time=0 us cost=4 size=36 card=1)
        200     INDEX RANGE SCAN XIF1_LEGAL_ENTITY_ID (cr=219 pr=77 pw=0 time=0 us cost=2 size=0 card=1)(object id 308082)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      ges message buffer allocation                8576        0.00          0.02
      library cache lock                              7        0.00          0.00
      library cache pin                               7        0.00          0.00
      SQL*Net message to client                      15        0.00          0.00
      Disk file operations I/O                       19        0.01          0.03
      gc cr grant 2-way                            8554        0.01          3.09
      db file sequential read                     14050        0.91        158.32
      SQL*Net message from client                    15       32.28         35.97
      gc cr grant congested                           8        0.00          0.01
    ********************************************************************************Plan with rare names.
    SELECT   customerin0_.ROW_NUMBER AS ROW1_22596_,
             customerin0_.ADDRESS_ID AS ADDRESS2_22596_,
             customerin0_.addressTypeId AS addressT3_22596_,
             customerin0_.city AS city22596_,
             customerin0_.CONTACT_DETAILS_CODE_ID AS CONTACT5_22596_,
             customerin0_.county AS county22596_,
             customerin0_.countyID AS countyID22596_,
             customerin0_.dob AS dob22596_,
             customerin0_.eyecolor AS eyecolor22596_,
             customerin0_.eyecolorid AS eyecolorid22596_,
             customerin0_.FIRST_NAME AS FIRST11_22596_,
             customerin0_.gender AS gender22596_,
             customerin0_.genderid AS genderid22596_,
             customerin0_.ID_NUMBER AS ID14_22596_,
             customerin0_.JURISDICTION_CODE AS JURISDI15_22596_,
             customerin0_.LAST_NAME AS LAST16_22596_,
             customerin0_.LEGAL_ENTITY_ID AS LEGAL17_22596_,
             customerin0_.LEGAL_ENTITY_NUMBER AS LEGAL18_22596_,
             customerin0_.LEGAL_ENTITY_TYPE AS LEGAL19_22596_,
             customerin0_.MIDDLE_NAME AS MIDDLE20_22596_,
             customerin0_.STREET_ADDRESS_1 AS STREET21_22596_,
             customerin0_.suffix_value AS suffix22_22596_,
             customerin0_.ZIP_CODE AS ZIP23_22596_,
             customerin0_.ZIP_PLUS_4 AS ZIP24_22596_
      FROM   xmatapp.CUSTOMER_IND_SEARCH_VIEW customerin0_
    WHERE       (customerin0_.LAST_NAME LIKE 'KUMAR%')
             AND customerin0_.genderid = '2'
             AND ROWNUM <= 200
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.05       0.07          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch       15      0.02       0.03          0       1829          0         200
    total       17      0.07       0.10          0       1829          0         200
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: SYS
    Rows     Row Source Operation
         23  TABLE ACCESS BY INDEX ROWID REF_COUNTIES (cr=37 pr=0 pw=0 time=0 us cost=1 size=12 card=1)
         23   INDEX UNIQUE SCAN XPK_REF_COUNTIES (cr=14 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308432)
          5  TABLE ACCESS BY INDEX ROWID REF_EYE_COLORS (cr=9 pr=0 pw=0 time=0 us cost=1 size=10 card=1)
          5   INDEX UNIQUE SCAN XPK_REF_EYE_COLORS (cr=4 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308404)
          1  TABLE ACCESS BY INDEX ROWID REF_GENDER (cr=2 pr=0 pw=0 time=0 us cost=1 size=9 card=1)
          1   INDEX UNIQUE SCAN XPK_REF_GENDER (cr=1 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308759)
        200  COUNT STOPKEY (cr=1781 pr=0 pw=0 time=15124 us)
        200   NESTED LOOPS OUTER (cr=1781 pr=0 pw=0 time=14726 us cost=103 size=1248 card=6)
        200    NESTED LOOPS  (cr=1383 pr=0 pw=0 time=35422 us cost=80 size=1032 card=6)
        200     NESTED LOOPS  (cr=980 pr=0 pw=0 time=20198 us cost=55 size=1092 card=12)
        200      NESTED LOOPS  (cr=741 pr=0 pw=0 time=15422 us cost=31 size=768 card=12)
        289       NESTED LOOPS  (cr=129 pr=0 pw=0 time=3648 us cost=7 size=492 card=12)
          1        TABLE ACCESS BY INDEX ROWID REF_CONTACT_DETAILS (cr=2 pr=0 pw=0 time=0 us cost=1 size=10 card=1)
          1         INDEX UNIQUE SCAN XAK1_REF_CD_VALUE (cr=1 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308425)
        289        TABLE ACCESS BY INDEX ROWID PERSON_PROFILE_NAMES (cr=127 pr=0 pw=0 time=3360 us cost=6 size=372 card=12)
        289         INDEX RANGE SCAN IDX$$_D7D50001 (cr=18 pr=0 pw=0 time=672 us cost=2 size=0 card=12)(object id 311149)
        200       TABLE ACCESS BY INDEX ROWID PERSON_PROFILE (cr=612 pr=0 pw=0 time=0 us cost=2 size=23 card=1)
        289        INDEX UNIQUE SCAN XPK_PERSON_PROFILE (cr=323 pr=0 pw=0 time=0 us cost=1 size=0 card=1)(object id 308484)
        200      TABLE ACCESS BY INDEX ROWID LEGAL_ENTITY (cr=239 pr=0 pw=0 time=0 us cost=2 size=27 card=1)
        200       INDEX UNIQUE SCAN XPK_LEGAL_ENTITY (cr=194 pr=0 pw=0 time=0 us cost=1 size=0 card=1)(object id 308494)
        200     TABLE ACCESS BY INDEX ROWID LEGAL_ENTITY_ADDRESSES (cr=403 pr=0 pw=0 time=0 us cost=3 size=81 card=1)
        200      INDEX RANGE SCAN LENUM_CODE_ID (cr=230 pr=0 pw=0 time=0 us cost=2 size=0 card=1)(object id 307952)
        200    TABLE ACCESS BY INDEX ROWID LEGAL_ENTITY_IDENTIFICATIONS (cr=398 pr=0 pw=0 time=0 us cost=4 size=36 card=1)
        200     INDEX RANGE SCAN XIF1_LEGAL_ENTITY_ID (cr=198 pr=0 pw=0 time=0 us cost=2 size=0 card=1)(object id 308082)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      ges message buffer allocation                  14        0.00          0.00
      library cache lock                              7        0.00          0.00
      library cache pin                               7        0.00          0.00
      KJC: Wait for msg sends to complete             2        0.00          0.00
      SQL*Net message to client                      15        0.00          0.00
      SQL*Net message from client                    15       18.88         21.81
    ********************************************************************************PERSONPROFILENAMES-16 Milion rows
    LEGALENTITYADDRESSES-34 Milion rows
    PERSONPROFILE-16 Milion rows
    LEGALENTITY 17 Milion rows
    refcontactdetails 45 rows
    Thanks

  • Dynamic sort help needed

    I am trying to implement a dynamic sort using pl/sql procedure
    with two IN params, which tell what column to sort by
    and wich direction. smth. like this
    procedure getEmployees (p_dept_no in employee.dept_no%type,
    p_sortBy in varchar2,
    p_sortDir in varchar2
    p_empl_cur in out emplCur
    ) is
    begin
    OPEN p_empl_cur
    FOR
    SELECT EMP_ID, F_NAME, L_NAME
    FROM EMPLOYEE
    WHERE DEPT_NO=p_dept_no
    ORDER BY p_sortBy p_sortDir ; --> this is the part that does not work
    -- I make sure that the params values are correct
    -- possible p_sortBy values: EMP_ID, F_NAME, L_NAME
    -- and p_sortDir: 'ASC' or 'DESC'
    end getEmployees;
    Thank you in advance.

    Try execute immediate.
    Some thing like this:
    PROCEDURE GETEMPLOYEES (P_DEPT_NO IN EMPLOYEE.DEPT_NO%TYPE,
    P_SORTBY IN VARCHAR2,
    P_SORTDIR IN VARCHAR2
    P_EMPL_CUR IN OUT EMPLCUR
    ) IS
    BEGIN
    OPEN P_EMPL_CUR
    FOR
    SORT_SQL := NULL;
    SORT_SQL := 'SELECT EMP_ID, F_NAME, L_NAME FROM EMPLOYEE'||
    ' WHERE DEPT_NO=P_DEPT_NO '||
    ' ORDER BY '||P_SORTBY||' '||P_SORTDIR||';'
    EXECUTE IMMEDIATE SORT_SQL INTO P_EMPL_CUR;
    Thanks
    Vasu
    I am trying to implement a dynamic sort using pl/sql procedure
    with two IN params, which tell what column to sort by
    and wich direction. smth. like this
    procedure getEmployees (p_dept_no in employee.dept_no%type,
    p_sortBy in varchar2,
    p_sortDir in varchar2
    p_empl_cur in out emplCur
    ) is
    begin
    OPEN p_empl_cur
    FOR
    SELECT EMP_ID, F_NAME, L_NAME
    FROM EMPLOYEE
    WHERE DEPT_NO=p_dept_no
    ORDER BY p_sortBy p_sortDir ; --> this is the part that does not work
    -- I make sure that the params values are correct
    -- possible p_sortBy values: EMP_ID, F_NAME, L_NAME
    -- and p_sortDir: 'ASC' or 'DESC'
    end getEmployees;
    Thank you in advance.

  • Advanced Group Sorting Help Needed

    In a previous thread,I was able to great two levels of hierarchy:
    1) Group by Case Worker
       2) All clients that pertained to their caseload (assigned client)
    The initial problem was, it was pulling duplicate records because each client had multiple instances of treatment plans, but I was more concerned about the most recent begin date. within Section Expert > Details, I use the following formula
    {AZCLPLAN.BEG_DATE} <> maximum ({AZCLPLAN.BEG_DATE}, {CDCLIENT.CASE_NUM})
    This successfully pulled the most recent treatment plan for the client record, ignoring all previous records. However, the case worker wants to see their caseload sorted by which treatment plans are ending first (AZCPLAN.END_DATE). When I add a new group END_DATE, move it up the hierarchy for sorting, it breaks my duplicate record sort rule.
    In laymen terms, after the report strips the duplicates only showing the most recent records, I want to do a sort by dates thereafter. how is this possible?

    I tried adding Record Sort Expert. By default the two hierarchy groups are locked at the top tiers. The 3rd item is solely the record file: ..END_DATE set to ascending.
    Under the Caseworker Group (highest tier) , next group in line is CASE_NUM. therefore, once a group is in place, it trumps anything below it (currently sorted by chart/case number). I tried changing the Group Expert > CASE_NUM to "original order" , but no luck.

  • Help needed in understanding the concept of hierarchical queries

    I really need help in this matter. I have a flafile containing about 4000 rows. It is from my supplier, it's structure is as follows:
    create table Flatfile
    (Pgroup varchar2(30),
    Pclass varchar2(30),
    Manufacturer varchar2(30),
    Article varchar2(30),
    Price Number(6,2));
    Insert into Flatfile Values
    ('Application Software','Database Software','Oracle','Oracle 10G',115);
    Insert into Flatfile Values
    ('Application Software','Database Software','Microsoft','MS SQL Server 2000',200);
    Insert into Flatfile Values
    ('Application Software','Spreadsheet Software','Microsoft','Excel',100);
    Insert into Flatfile Values
    ('Monitor','15"','Acer','Acer 15"" TFT superscreen',199);
    Insert into Flatfile Values
    ('Monitor','15"','Sony','Sony R1500 flat',225);
    Insert into Flatfile Values
    ('Monitor','17"','Philips','Philips Flatscreen',250);
    Insert into Flatfile Values
    ('Monitor','19"','Viewsonic','Viewsonic PLasma Monitor',275);
    Insert into Flatfile Values
    ('Processor','AMD','AMD','FX-55',600);
    Insert into Flatfile Values
    ('Processor','Intel','Intel','P4 3 GHZ',399);
    My goal is to make a hierarchical query with the start with and connect by clauses. From what I have read is that I need to normalize the data of the flatfile.
    How do I achieve a table which I can query so that the query will represent the hierarchy that exists. Namely
    Pgroup
    ++Pclasse
    Application Software
    ++Database Software
    ++Spreadsheet Software
    So a 2-level hierarchy. I'd like to understand this simple concept first. I built on the knowledge that I gain. So the questions are:
    1.What do I need to do to make the table so that I can use a hierarchical query on it?
    2. How should the query syntax be?
    3. Is it also possible to get the data in the hierarchical query sorted asec?
    I would only like to use the simple structures of the start with and connect by clauses first. I've read there are some new additions to 10G. The problem with the examples used by the tutorials is that the tables are already made so that they are suitable for hierarchical queries. I hope to understand it by this example. And take it a step further.
    Sincerely,
    Pete

    Primarily hierarchy query serves to process tree-like structures which RDBMS simulates using through parent-child relation, often in a single table (see famoust
    EMP table where employee can have the manager who is an employee at the same time).
    In your case it could look like:
    SQL> select pgroup, pclass from flatfile;
    PGROUP                         PCLASS
    Application Software           Database Software
    Application Software           Database Software
    Application Software           Spreadsheet Software
    Monitor                        15"
    Monitor                        15"
    Monitor                        17"
    Monitor                        19"
    Processor                      AMD
    Processor                      Intel
                                   Application Software
                                   Monitor
                                   Processor
    12 rows selected.
    SQL> select decode(level,1,pclass,'  ' || pclass), Manufacturer from flatfile
      2  start with pgroup is null
      3  connect by prior pclass = pgroup
      4  /
    DECODE(LEVEL,1,PCLASS,''||PCLASS MANUFACTURER
    Application Software
      Database Software              Oracle
      Database Software              Microsoft
      Spreadsheet Software           Microsoft
    Monitor
      15"                            Acer
      15"                            Sony
      17"                            Philips
      19"                            Viewsonic
    Processor
      AMD                            AMD
      Intel                          Intel
    12 rows selected.The hierarchy syntax is described completely in the documentation including
    LEVEL and PRIOR keywords.
    As for the ordering question you can use siblings ordering:
    SQL> select decode(level,1,pclass,'  ' || pclass), Manufacturer from flatfile
      2  start with pgroup is null
      3  connect by prior pclass = pgroup
      4  order siblings by 1 desc
      5  /
    DECODE(LEVEL,1,PCLASS,''||PCLASS MANUFACTURER
    Processor
      Intel                          Intel
      AMD                            AMD
    Monitor
      19"                            Viewsonic
      17"                            Philips
      15"                            Acer
      15"                            Sony
    Application Software
      Spreadsheet Software           Microsoft
      Database Software              Oracle
      Database Software              Microsoft
    12 rows selected.Rgds.

  • [Oracle 8i] Need help pruning branches from a hierarchical query

    My problem is that my hierarchical query seems only to trim out the values that don't meet my criteria, but still includes their children. When my query hits a record that does not meet my criteria, I want it to stop there. I've tried including the criteria in just the 'where' clause of the query, and have also put the criteria in the 'connect by' clause as well, but nothing has fixed it. Please keep in mind I'm using Oracle 8i, so I can't use some of the 'nicer' statements for hierarchical queries that they introduced in 9. I'm stuck with 'Start With...Connect By'.
    I have sample tables/data that I can post if someone needs to see that to help me, but to start with, here's my current query:
    SELECT     *
    FROM     (
              SELECT
                   LEVEL
              ,     c_bill.comp_part_nbr                     AS     c_part_nbr
              ,     (select c_part.part_desc
                   FROM part c_part
                   WHERE c_part.part_nbr=c_bill.comp_part_nbr)     AS     c_part_desc
              ,     (SELECT c_part.part_type
                   FROM part c_part
                   WHERE c_part.part_nbr=c_bill.comp_part_nbr)      AS     c_part_type
              ,     c_bill.qty_per                          AS     c_qty_per_p
              ,     c_bill.qty_per_type                     AS     c_qty_per_type
              ,     (SELECT c_part.qty_on_hand                
                   FROM part c_part
                   WHERE c_part.part_nbr=c_bill.comp_part_nbr)      AS     c_qty_on_hand
              ,     c_bill.oper_nbr                     AS     rqd_at_op
              ,     c_bill.comp_off_adj                     AS     rqd_offset
              ,     c_bill.bom_doc_nbr                     AS     p_part_nbr
              ,     (SELECT p_part.qty_on_hand
                   FROM part p_part
                   WHERE p_part.part_nbr=c_bill.bom_doc_nbr)      AS     p_qty_on_hand
              FROM
                   BILL c_bill
              WHERE
                             (c_bill.status           =      'RL')           
                        AND     (c_bill.view_code     IN      ('M','G'))     
                        AND     (c_bill.end_eff_dt     >      SYSDATE)      
                        AND     (c_bill.begn_eff_dt     <=      SYSDATE)
              START WITH c_bill.bom_doc_nbr=RPAD(?,25)
              CONNECT BY PRIOR c_bill.comp_part_nbr=c_bill.bom_doc_nbr
              AND     c_bill.view_code     IN     ('M','G')     
              AND     c_bill.status          =     'RL'
              AND      c_bill.end_eff_dt     >     SYSDATE
              AND     c_bill.begn_eff_dt     <=     SYSDATE     
         ) a
    WHERE     c_part_type = 'M'

    The outside criterion of part_type='M' isn't my problem. Where I'm actually seeing my issue rear its ugly head is in the criterion:
    (c_bill.view_code     IN      ('M','G'))What I'll have happen is that one of the children or grandchildren of the part number I'm querying for (my parameter), will be of some view code that's not 'M' or 'G'. In my sample data below, I have a level 4 part that is part of the 'H' view code, which I don't want, nor do I want it's children. However, its child is in the 'G' view code, and my query returns it anyway.
    In my sample data below, I'm assuming that the parameter = 'XYZ-100'
    CREATE TABLE part
    part_nbr     varchar(25) not null,
    part_desc     varchar(25) not null,
    part_type     char(1) not null,
    qty_on_hand     double(13,4) not null
    CONSTRAINT part_pk
    PRIMARY KEY (part_nbr),
    CONSTRAINT check_part_type
    CHECK (part_type IN ('M','P','X','Y')),
    CONSTRAINT check_qty_on_hand
    CHECK (qty_on_hand >= 0)
    CREATE TABLE bill
    row_added_ts     char(20) not null,
    bom_doc_nbr     varchar(25) not null,
    comp_part_nbr     varchar(25) not null,
    qty_per          double(9,5) not null,
    qty_per_type     char(1) not null,
    oper_nbr     char(4) not null,
    comp_off_adj     double(3,0),
    status          char(2),
    view_code     char(1) not null,
    end_eff_dt     date() not null,
    begn_eff_dt     date() not null
    CONSTRAINT bill_pk
    PRIMARY KEY (row_added_ts),
    CONSTRAINT check_qty_per_type
    CHECK (qty_per_type IN ('0','1','2','3')),
    CONSTRAINT check_status
    CHECK (status IN ('IN', 'RL')),
    );     Values for those tables:
    INSERT INTO part
    VALUES ('xyz-1', 'purchased part', 'P', 5);
    INSERT INTO part
    VALUES ('xyz-2', 'purchased part', 'P', 1);
    INSERT INTO part
    VALUES ('xyz-3', 'purchased part', 'P', 1);
    INSERT INTO part
    VALUES ('xyz-3a', 'manufactured part', 'M', 1);
    INSERT INTO part
    VALUES ('xyz-4', 'purchased part', 'P', 1);
    INSERT INTO part
    VALUES ('xyz-9-1', 'manufactured part', 'M', 0);
    INSERT INTO part
    VALUES ('xyz-9a', 'manufactured part', 'M', 0);
    INSERT INTO part
    VALUES ('raw-1', 'purchased raw material', 'P', 212);
    INSERT INTO part
    VALUES ('raw-2', 'purchased raw material', 'P', 75.5);
    INSERT INTO part
    VALUES ('XYZ-100', 'manufactured part', 'M', 0);
    INSERT INTO part
    VALUES ('(OPEN)', '(not in use)', 'Y', 0);
    INSERT INTO part
    VALUES ('XYZ-100-1', 'manufactured part', 'M', 0);
    INSERT INTO part
    VALUES ('XYZ-100-2', 'manufactured part', 'M', 1);
    INSERT INTO part
    VALUES ('XYZ-100-3', 'manufactured part', 'M', 0);
    INSERT INTO part
    VALUES ('XYZ-100-4', 'manufactured part', 'M', 2);
    INSERT INTO part
    VALUES ('XYZ-100-A', 'manufactured part', 'M', 0);
    INSERT INTO bill
    VALUES ('2008072153100150000','XYZ-100','xyz-1',3,'1','****',0,'RL','M','01-Jan-2050','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008072153100150000','XYZ-100','XYZ-100-1',1,'1','****',0,'RL','M','01-Jan-2050','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008072153100150000','XYZ-100-1','xyz-1',2,'1','****',1,'RL','M','01-Jan-2050','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008072153100150000','XYZ-100-1','XYZ-100-2',3,'1','****',0,'RL','M','01-Jan-2050','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008072153100150000','XYZ-100-2','xyz-2',6,'1','****',2,'RL','M','01-Jan-2050','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008072153100150000','XYZ-100-2','xyz-4',6,'1','****',2,'IN','M','01-Jan-2050','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008072153100150000','XYZ-100-2','xyz-100-3',1,'1','****',0,'RL','M','01-Jan-2050','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008072153100150000','XYZ-100-3','xyz-3',8,'1','****',1,'RL','M','01-Jan-2050','01-Jan-2000');
    INSERT INTO bill
    VALUES ('2008072153100150000','XYZ-100-3','xyz-3a',8,'1','****',1,'RL','M','01-Jan-2000','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008072153100150000','XYZ-100-3','XYZ-100-4',4,'1','****',0,'RL','M','01-Jan-2050','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008072153100150000','XYZ-100-3','XYZ-100-A',2,'1','****',2,'RL','M','01-Jan-2050','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008071153100150000','XYZ-100-3','(OPEN)',2,'1','****',0,'RL','E','01-Jan-2050','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008071153100150000','XYZ-100-3','xyz-9-1',2,'1','****',0,'RL','H','01-Jan-2050','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008072153100150000','XYZ-100-4','raw-1',8.75,'1','****',0,'RL','M','01-Jan-2050','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008072153100150000','XYZ-100-A','raw-2',3.75,'1','****',0,'RL','M','01-Jan-2050','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008075911100150000','xyz-9-1','xyz-9a',1,'1','****',0,'RL','G','01-Jan-2050','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008087711100150000','xyz-9a','raw-2',3.75,'1','****',0,'RL','G','01-Jan-2050','01-Jan-1900');Sample data displayed in table format:
    --PART table (from insert statements above)
    part_nbr     part_desc          part_type     qty_on_hand
    xyz-1           purchased part          P          5
    xyz-2           purchased part          P          1
    xyz-3           purchased part          P          1
    xyz-3a           manufactured part     M          1
    xyz-4           purchased part          P          1
    xyz-9-1           manufactured part     M          0
    xyz-9a           manufactured part     M          0
    raw-1           purchased raw material     P          212
    raw-2           purchased raw material     P          75.5
    XYZ-100           manufactured part     M          0
    (OPEN)          (not in use)          Y          0
    XYZ-100-1     manufactured part     M          0
    XYZ-100-2     manufactured part     M          1
    XYZ-100-3     manufactured part     M          0
    XYZ-100-4     manufactured part     M          2
    XYZ-100-A     manufactured part     M          0
    --BILL table (from insert statements above)
    row_added_ts          bom_doc_nbr     comp_part_nbr     qty_per     qty_per_type     oper_nbr     comp_off_adj     status     view_code     end_eff_dt     begn_eff_dt
    2008072153100150000     XYZ-100          xyz-1          3     1          ****          0          RL     G          01-Jan-2050     01-Jan-1900
    2008072223100150000     XYZ-100          XYZ-100-1     1     1          ****          0          RL     M          01-Jan-2050     01-Jan-1900
    2008072411100150000     XYZ-100-1     xyz-1          2     1          ****          1          RL     M          01-Jan-2050     01-Jan-1900
    2008072459100150000     XYZ-100-1     XYZ-100-2     3     1          ****          0          RL     M          01-Jan-2050     01-Jan-1900
    2008072578100150000     XYZ-100-2     xyz-2          6     1          ****          2          RL     M          01-Jan-2050     01-Jan-1900
    2008072694100150000     XYZ-100-2     xyz-4          6     1          ****          2          IN     G          01-Jan-2050     01-Jan-1900
    2008072786100150000     XYZ-100-2     xyz-100-3     1     1          ****          0          RL     M          01-Jan-2050     01-Jan-1900
    2008072865100150000     XYZ-100-3     xyz-3          8     1          ****          1          RL     M          01-Jan-2050     01-Jan-2000
    2008073100100150000     XYZ-100-3     xyz-3a          8     1          ****          1          RL     M          01-Jan-2000     01-Jan-1900
    2008073159100150000     XYZ-100-3     XYZ-100-4     4     1          ****          0          RL     M          01-Jan-2050     01-Jan-1900
    2008073346100150000     XYZ-100-3     XYZ-100-A     2     1          ****          2          RL     M          01-Jan-2050     01-Jan-1900
    2008073478100150000     XYZ-100-3     (OPEN)          2     1          ****          0          RL     E          01-Jan-2050     01-Jan-1900
    2008073529100150000     XYZ-100-3     xyz-9-1          2     1          ****          0          RL     H          01-Jan-2050     01-Jan-1900
    2008073798100150000     XYZ-100-4     raw-1          8.75     1          ****          0          RL     M          01-Jan-2050     01-Jan-1900
    2008073811100150000     XYZ-100-A     raw-2          3.75     1          ****          0          RL     M          01-Jan-2050     01-Jan-1900
    2008075911100150000     xyz-9-1          xyz-9a          1     1          ****          0          RL     G          01-Jan-2050     01-Jan-1900
    2008087711100150000     xyz-9a          raw-2          3.75     1          ****          0          RL     G          01-Jan-2050     01-Jan-1900--What I want to get with my query (branches pruned off my tree)
    LEVEL     C_PART_NBR     C_PART_DESC          C_PART_TYPE     C_QTY_PER_P     C_QTY_PER_TYPE     C_QTY_ON_HAND     RQD_AT_OP     RQD_OFFSET     P_PART_NBR     P_QTY_ON_HAND
    1     XYZ-100-1     manufactured part     M          1          1          0          ****          0          XYZ-100          0
    2     XYZ-100-2     manufactured part     M          3          1          1          ****          0          XYZ-100-1     0
    3     xyz-100-3     manufactured part     M          1          1          0          ****          0          XYZ-100-2     1
    4     XYZ-100-4     manufactured part     M          4          1          2          ****          0          XYZ-100-3     0
    4     XYZ-100-A     manufactured part     M          2          1          0          ****          2          XYZ-100-3     0--What I actually get with my query (includes children of items that don't meet query criteria)
    LEVEL     C_PART_NBR     C_PART_DESC          C_PART_TYPE     C_QTY_PER_P     C_QTY_PER_TYPE     C_QTY_ON_HAND     RQD_AT_OP     RQD_OFFSET     P_PART_NBR     P_QTY_ON_HAND
    1     XYZ-100-1     manufactured part     M          1          1          0          ****          0          XYZ-100          0
    2     XYZ-100-2     manufactured part     M          3          1          1          ****          0          XYZ-100-1     0
    3     xyz-100-3     manufactured part     M          1          1          0          ****          0          XYZ-100-2     1
    4     XYZ-100-4     manufactured part     M          4          1          2          ****          0          XYZ-100-3     0
    4     XYZ-100-A     manufactured part     M          2          1          0          ****          2          XYZ-100-3     0
    5     xyz-9a          manufactured part     M          1          1          0          ****          0          xyz-9-1          0Edited by: user11033437 on Jul 30, 2009 7:27 AM (grammar)

  • Help need in hierarchy query

    Hi,
    I need to display the parent child nodes in the hierarchical manner and i need to list the user under their hier name in the same hierarchical structure. table structures are all as follows.
    user table:
    * userid name*
    100 john
    101 shaddy
    102 sandy
    103 Kalinich
    104 king
    105 Teresa
    106 Clinia
    user hier table :
    userid  hier name
    100 node1
    101 node2
    102 node1
    103 node2
    104 parent
    105 node4
    106 node
    hier table:
    id hier name parent_id
    1 parent
    2 node 1
    3 node1 2
    4 node2 2
    5 node3 1
    6 node4 5
    7 node5 5
    o/p :
    104 king
    106 clinia
    100 john
    102 sandy
    103 Kalinich
    101 shaddy
    105 terresa
    even we dont have entry in user hier and user table for node3 we need to display them child users under the "parent" hier name and need to ignore the child nodes which dont have users under them i.e) need to ignore node5 in the output. below is the query which I have tried.
    SELECT NAME,u.name
    FROM user_hier n,hier u,user a
    WHERE a.user_id (+) = u.user_id
    AND u.name (+) = n.name
    START WITH n.name = 'parent'
    CONNECT BY PRIOR n.node_id= n.parent_node_id;
    Help me on this.
    Thanks in advance
    Edited by: Vi on Apr 30, 2012 6:10 AM

    No you haven't. Either post create table statements or set up your data with a WITH clause, something like the following example:
    with USER_TABLE as (
      select 100 userid, 'john' name from dual union all
      select 101 userid, 'shaddy' name from dual union all
      select 102 userid, 'sandy' name from dual union all
      select 103 userid, 'Kalinich' name from dual union all
      select 104 userid, 'king' name from dual union all
      select 105 userid, 'Teresa' name from dual union all
      select 106 userid, 'Clinia' name from dual
    select * from USER_TABLE
        USERID NAME
           100 john
           101 shaddy
           102 sandy
           103 Kalinich
           104 king
           105 Teresa
           106 Clinia
    7 rows selected.

  • Hierarchical Query Help

    Version: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    Hello,
    I'm hoping I can get help with a Hierarchical Query.
    My base table contains Projects with a Group ID. Each Group can have the same Project Name so displaying the information in a Select List on an form for data entry can be very confusing. I'm hoping I can get a query that would produce the output below.
    Please let me know if I haven't provided the necessary information.
    The tables involved are:
    CREATE TABLE projects
      PROJECT_ID             NUMBER,
      PROJECT_NAME           VARCHAR2(100),
      GROUP_ID               NUMBER
    CREATE TABLE vertical_group
      GROUP_ID      NUMBER,
      GROUP_NAME    VARCHAR2(50)
    The data is:
    INSERT INTO projects(project_id,project_name,group_id)
    VALUES (1,'Proj Grp 1',1);
    INSERT INTO projects(project_id,project_name,group_id)
    VALUES (2,'Proj Grp 1',1);
    INSERT INTO projects(project_id,project_name,group_id)
    VALUES (3,'Proj Grp 1',1);
    INSERT INTO projects(project_id,project_name,group_id)
    VALUES (4,'Proj Grp 1',1);
    INSERT INTO projects(project_id,project_name,group_id)
    VALUES (5,'Proj Grp 1',1);
    INSERT INTO projects(project_id,project_name,group_id)
    VALUES (6,'Proj Grp 2',2);
    INSERT INTO projects(project_id,project_name,group_id)
    VALUES (7,'Proj Grp 2',2);
    INSERT INTO projects(project_id,project_name,group_id)
    VALUES (8,'Proj Grp 2',2);
    INSERT INTO projects(project_id,project_name,group_id)
    VALUES (9,'Proj Grp 2',2);
    INSERT INTO projects(project_id,project_name,group_id)
    VALUES (10,'Proj Grp 3',3);
    INSERT INTO projects(project_id,project_name,group_id)
    VALUES (11,'Proj Grp 3',3);
    INSERT INTO projects(project_id,project_name,group_id)
    VALUES (12,'Proj Grp 3',3);
    INSERT INTO vertical_group(group_id,group_name)
    VALUES (1,'Group 1');
    INSERT INTO vertical_group(group_id,group_name)
    VALUES (2,'Group 2');
    INSERT INTO vertical_group(group_id,group_name)
    VALUES (3,'Group 3');
    The desired output is:
    Group 1
        Proj Grp 1
        Proj Grp 1
        Proj Grp 1
        Proj Grp 1
        Proj Grp 1
    Group 2
        Proj Grp 2
        Proj Grp 2
        Proj Grp 2
        Proj Grp 2
    Group 3
        Proj Grp 3
        Proj Grp 3
        Proj Grp 3
    Thanks,
    Joe

    No hierarchical query is needed. Use UNION ALL and weights:
    with t as (
                select  'Group ' || group_id name,
                        group_id,
                        1 weight
                  from  projects
                  group by group_id
               union all
                select  '  ' || project_name,
                        group_id,
                        2 weight
                  from  projects
    select  name
      from  t
      order by group_id,
               weight,
               name
    NAME
    Group 1
      Proj Grp 1
      Proj Grp 1
      Proj Grp 1
      Proj Grp 1
      Proj Grp 1
    Group 2
      Proj Grp 2
      Proj Grp 2
      Proj Grp 2
      Proj Grp 2
    NAME
    Group 3
      Proj Grp 3
      Proj Grp 3
      Proj Grp 3
    15 rows selected.
    SQL>
    SY.

Maybe you are looking for

  • How can I see previously ViewNX2-edited photos (raw) in Lightroom 3?

    I recently bought Lightroom 3, and after importing my previously ViewNX 2-edited photos (in RAW, NEF), I saw that Lightroom doesn't show those changes. I can only see the photos in its original form. Is there a way to import them to Lightroom 3 and s

  • Spatial Query Response Time

    O/S - Sun Solaris ver - Oracle 8.1.7 I am trying to improve the response time of the following query. Both tables contain polygons. select a.data_id, a.GEOLOC from information_data a, shape_data b where a.info_id = 2 and b.shape_id = 271 and sdo_filt

  • Load balancing  in dual stack

    Hi all, we have  SRM 5.0 which is clustered with one apps server....     SMLG is configured and load balancing is not going well , all the load is going directly to CI  not to apps server... In BI [dual stack] portal  the connection to SRM in system

  • WD Passport not mounted and not seen in Disk Utility, but something seen in Terminal

    Hi, I have a WD 1TB Passport external hard drive.  THe light comes on and the disc spins, but I can't see the hard drive in disk utilitiy or anywhere else.  I know that it connects.  I saw a post about using terminal to mount using code, but it never

  • Creation of pooled capacity

    Hi all, I would like to create a new pooled capacity for resource X. Please help me how to proceed? Is there any place in customizing where we need to maintain it? Or do we need to configure it?Please provide me the steps. Thanks in advance Regards A