How to create a conuntry Hierarchy

For anyone who need...
create or replace procedure prc_path IS
cursor cun is
select distinct country
from test1;
cursor reg(v_con varchar2) is
select distinct region
from test1
where country = v_con;
cursor st(v_con varchar2 , v_reg varchar2) is
select distinct state
from  test1
where country = v_con
and   region  = v_reg ;
cursor ct(v_con varchar2 , v_reg varchar2 , v_st varchar2) is
select distinct city
from  test1
where country = v_con
and   region  = v_reg
and   state   = v_st;
v_con_num number := 1;
v_reg_num number;
v_st_num number;
v_ct_num number;
v_hir_key number;
begin
delete from bus_unit;
delete from bushirkey;
for r_cun in cun loop
dbms_output.put_line('<1st loop> Country Name : '||r_cun.country);
insert into bus_unit (busunitkey , busunitname)
values (v_con_num , r_cun.country);
insert into bushirkey (busunitkey , hirkey)
values (v_con_num , 0);
v_con_num := v_con_num + 1 ;
end loop;
v_reg_num := v_con_num ;
for r_cun in cun loop
  for r_reg in reg(r_cun.country) loop
    dbms_output.put_line('<2nd loop> Country Name : '||r_cun.country);
    dbms_output.put_line('<2nd loop> Region Name : '||r_reg.region);
    insert into bus_unit (busunitkey , busunitname)
    values (v_reg_num , r_reg.region);
    select distinct busunitkey
    into v_hir_key
    from bus_unit
    where busunitname = r_cun.country;
    insert into bushirkey (busunitkey , hirkey)
    values (v_reg_num , v_hir_key);
    v_reg_num := v_reg_num + 1 ;
  end loop;
end loop;
v_st_num := v_reg_num;
for r_cun in cun loop
  for r_reg in reg(r_cun.country) loop
    for r_st in st(r_cun.country,r_reg.region) loop
      dbms_output.put_line('<3rd loop> Country Name : '||r_cun.country);
      dbms_output.put_line('<3rd loop> Region Name : '||r_reg.region);
      dbms_output.put_line('<3rd loop> State Name : '||r_st.state);
      insert into bus_unit (busunitkey , busunitname)
      values (v_st_num , r_st.state);
      select distinct busunitkey
      into v_hir_key
      from bus_unit
      where busunitname = r_reg.region;
      insert into bushirkey (busunitkey , hirkey)
      values (v_st_num , v_hir_key);
      v_st_num := v_st_num + 1 ;
    end loop;
  end loop;
end loop;
v_ct_num := v_st_num;
for r_cun in cun loop
  for r_reg in reg(r_cun.country) loop
    for r_st in st(r_cun.country,r_reg.region) loop
      for r_ct in ct(r_cun.country,r_reg.region,r_st.state) loop
        dbms_output.put_line('<4th loop> Country Name : '||r_cun.country);
        dbms_output.put_line('<4th loop> Region Name : '||r_reg.region);
        dbms_output.put_line('<4th loop> State Name : '||r_st.state);
        dbms_output.put_line('<4th loop> City Name : '||r_ct.city);
        insert into bus_unit (busunitkey , busunitname)
        values (v_ct_num , r_ct.city);
        select distinct busunitkey
        into v_hir_key
        from bus_unit
        where busunitname = r_st.state;
        insert into bushirkey (busunitkey , hirkey)
        values (v_ct_num , v_hir_key);
        v_ct_num := v_ct_num + 1 ;
      end loop;
    end loop;
  end loop;
end loop;
exception
when others then
dbms_output.put_line('ERROR'||SQLERRM);
end;Edited by: BluShadow on 17-Mar-2011 11:33
added {noformat}{noformat} tags to preserve formatting (what little of it there is)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

user1642876 wrote:
i want to know what other ways to get...You could refactor your code like this:
SQL> create or replace procedure prc_path
  2  is
  3  begin
  4    insert all
  5           into bus_unit (busunitkey,busunitname)
  6           values (area_key,area_name)
  7           into bushirkey (busunitkey,hirkey)
  8           values (area_key,parent_key)
  9    with all_areas as
10    ( select distinct null parent_name
11           , country name
12        from test1
13       union all
14      select distinct country
15           , region
16        from test1
17       union all
18      select distinct region
19           , state
20        from test1
21       union all
22      select distinct state
23           , city
24        from test1
25    )
26    , all_areas_with_numbers as
27    ( select rownum key
28           , parent_name
29           , name
30        from all_areas
31    )
32    select a.key area_key
33         , a.name area_name
34         , nvl(p.key,0) parent_key
35      from all_areas_with_numbers a
36         , all_areas_with_numbers p
37     where a.parent_name = p.name (+)
38    ;
39  end prc_path;
40  /If I test it with these tables:
SQL> create table test1 (country,region,state,city)
  2  as
  3  select 'USA','West USA','California','San Francisco' from dual union all
  4  select 'USA','West USA','California','Los Angeles' from dual union all
  5  select 'USA','West USA','Washington','Seattle' from dual union all
  6  select 'USA','East USA','Florida','Miami' from dual union all
  7  select 'USA','East USA','Florida','Orlando' from dual
  8  /
Table created.
SQL> create table bus_unit
  2  ( busunitkey  number
  3  , busunitname varchar2(30)
  4  )
  5  /
Table created.
SQL> create table bushirkey
  2  ( busunitkey number
  3  , hirkey     number
  4  )
  5  /
Table created.Then your procedure gives you this:
SQL> exec prc_path
<1st loop> Country Name : USA
<2nd loop> Country Name : USA
<2nd loop> Region Name : East USA
<2nd loop> Country Name : USA
<2nd loop> Region Name : West USA
<3rd loop> Country Name : USA
<3rd loop> Region Name : East USA
<3rd loop> State Name : Florida
<3rd loop> Country Name : USA
<3rd loop> Region Name : West USA
<3rd loop> State Name : California
<3rd loop> Country Name : USA
<3rd loop> Region Name : West USA
<3rd loop> State Name : Washington
<4th loop> Country Name : USA
<4th loop> Region Name : East USA
<4th loop> State Name : Florida
<4th loop> City Name : Miami
<4th loop> Country Name : USA
<4th loop> Region Name : East USA
<4th loop> State Name : Florida
<4th loop> City Name : Orlando
<4th loop> Country Name : USA
<4th loop> Region Name : West USA
<4th loop> State Name : California
<4th loop> City Name : Los Angeles
<4th loop> Country Name : USA
<4th loop> Region Name : West USA
<4th loop> State Name : California
<4th loop> City Name : San Francisco
<4th loop> Country Name : USA
<4th loop> Region Name : West USA
<4th loop> State Name : Washington
<4th loop> City Name : Seattle
PL/SQL procedure successfully completed.
SQL> select *
  2    from bus_unit
  3   order by busunitkey
  4  /
BUSUNITKEY BUSUNITNAME
         1 USA
         2 East USA
         3 West USA
         4 Florida
         5 California
         6 Washington
         7 Miami
         8 Orlando
         9 Los Angeles
        10 San Francisco
        11 Seattle
11 rows selected.
SQL> select *
  2    from bushirkey
  3   order by busunitkey
  4  /
BUSUNITKEY     HIRKEY
         1          0
         2          1
         3          1
         4          2
         5          3
         6          3
         7          4
         8          4
         9          5
        10          5
        11          6
11 rows selected.And the new code gives:
SQL> exec prc_path
PL/SQL procedure successfully completed.
SQL> select *
  2    from bus_unit
  3   order by busunitkey
  4  /
BUSUNITKEY BUSUNITNAME
         1 USA
         2 East USA
         3 West USA
         4 Florida
         5 California
         6 Washington
         7 Los Angeles
         8 San Francisco
         9 Miami
        10 Orlando
        11 Seattle
11 rows selected.
SQL> select *
  2    from bushirkey
  3   order by busunitkey
  4  /
BUSUNITKEY     HIRKEY
         1          0
         2          1
         3          1
         4          2
         5          3
         6          3
         7          5
         8          5
         9          4
        10          4
        11          6
11 rows selected.Regards,
Rob.

Similar Messages

  • How to create the Product Hierarchy maintenance ..?

    Hi All,
    How to create the Product Hierarchy maintenance (IN APO System), I know manual creation, going to the transaction : /n/sapapo/relhshow , how to create programmatically, is there any Function module?
    Pls let me know
    Puppy.

    Hi Puppy,
    Please check whether the below BAPI can be used by you.
    T-code: BAPI
    Object name: ProductAllocationAPO
    Obj type:- BUS11305
    Regards
    R. Senthil Mareeswaran.

  • How to create a Case Hierarchy

    Hi Friends,
    Can you pls guide me on how to create a Case Hierarchy?
    It's very much urgent.
    Thanks in advance and warm regards
    Purnendu

    Hello,
    Please have follow below steps for case hierarchy,we have implemented for service scenario
    General paths:
    CRM/Case Management/
    CRM/Interaction Center Web Client/Business Transactions/Case Management
    Transaction:
    SCASE_CUSTOMIZING
    Basic Settings
    Number range defined
    Case type emergency defined
    Status Settings
    Case status profile defined with values as below
    Case attribute settings
    Case priority defined (general for all case types)
    Case reason defined
    Case Category defined
    Create function profile and assign to Case Type
    ICWebclient settings
    Define and Enhance ICWeb client profile for Case processing
    Case Search added to Z_XXXX Nav Bar and new Z_XXXX_Case defined. New Nav Bar has Case Management Entry added.
    Additional ICWeb client profile defined. Assign new Nav Bar assigned and Case function profile to the new profile.
    Assign function profile for ICWebclient
    Create new runtime profile and assign to new ICWeb client profile. Also replace appropriate controllers for Case Management. Pls refer to Technical Specification for details.
    Case Record Model (transaction scase)
    RMS ID
    Case Record Model – Cycle0 activity. View for linking business objects to Case record.
    Set Up Registry
    Include new record model and service provider for record model in Case Type
    Maintain filters in ICWeb
    Column headings
    BOL paths, mapper classes and search help for CSRs.
    Define Filter profile
    Maintain entries to Filter profile.
    Assign Filter profile to Case Type
    New Business activities for Case
    Transaction type Case activity , partner determination and status profile created. 
    Status profiles for new business activities
    Partner Determination procedures for new business activites
    Regrds
    Shanmuga

  • How to create material group hierarchy ?

    Hi,
    I would like to know how to create material group hierarchy in ECC 6.0
    Thanks in advance for your help,
    Kind regards,
    Yann

    Hi ,
    The material group hierarchy and product heirarchy is used in SD of ECC 6.0 . These can be created in Logistics General -> Material Master-> settings for Key fields--> Data Relevant to Sales and Distribution-> 1)
    define product categories
    2)Define material groups
    But If you want to make of use of this in SRM ,I won't think it is available . I guess Probably this is avl for CRM .
    Regards
    Mani
    Message was edited by:
            Manikanda Ilango S.

  • How to create a custom Hierarchy in IDT 4.0

    Hi All.
    I am trying to create a custom hierarchy objects in the Information Design tool, But I am not able to find it here as same sort like the universe designer in 3.1 or 4.0 . I have found the navigational path but I am not sure how I can use it as a hierarchical objects in my reports, Can anyone please suggest how to create a custom hierarchical dimension in IDT 4.0.
    Thanks,
    Navin

    Custom Hierarchy are called navigation path in IDT. I will suggest to go through the navigation path tutorials below
    http://scn.sap.com/docs/DOC-22087
    Hierarchical objects are no different than any regular objects but they enable the drilling in drill mode in the report and you can create a cascading prompt on top of them..
    If after going through this you still have any specific questions just let us know...

  • How to Create and External Hierarchy and group values of IO in node

    Good morning
    BI 7:
    Please give me guidance on the following?
    I need to either to restrict a characteristic in a query to more than 800 values OR exclude values where it contains the pattern 'Z7' and 'Z8'. There are thousands of values which contains the pattern and they are not listed in such a way that I can exclude them as a value range, thus I would have to include all the values I want into the restriction, which is more than 800. An error displays when I check the query:
    ""In the structural component Warranty Damage Code, characteristic ZWR_DMGC is restricted to 838 values. This number is very large and will probably meet with technical limitations""
    The proposed solution is:
    ""Create an external hierarchy for characteristic ZWR_DMGC and group the 838 values in a hierarchy node. You can then work with the node instead of the 838 individual values.
    Alternatively, you can define a corresponding navigation attribute for ZWR_DMGC""
    I know where to create the hierarchy, but I am confused how to only include the values of the applicable IO where pattern contains 'Z7' and 'Z8'.......??
    The following are some of the steps proposed in a related thread, but I am loosing it at step 7.
    5. Confirm your entries. The Maintain Hierarchy screen appears. You can define the structure of a hierarchy here. ok
    6. To create a hierarchy node, you first need to choose an insertion mode: Insert as First Child or Insert As Next Neighbor (see Hierarchy Editing Functions). I selected first child
    7. Choose the type of node you want to create: Text Node, Characteristic Node, <Hierarchy Basic Characteristic Node> or Interval (see Hierarchy Nodes) *this is where I am lost, which should I select to list values with pattern ' *Z7' and ' Z8' in a node or two
    8. Repeat this procedure until the hierarchy structure has been set. For more information, see Modeling Nodes and Leaves.
    A hierarchy can contain 50,000-100,000 leaves at most. If your hierarchy is larger, you should insert a level that is used as a navigation attribute or preferably as a separate characteristic in the dimension table.
    9. You can use Level Maintenance and Hierarchy Attributes to set how the hierarchy is to be displayed and processed in reporting (see Level Maintenance and Hierarchy Attributes).
    10. Save the hierarchy.
    Your assistance will be appreciated.

    Hierarchy not used in this case. Could not fnd an answer.

  • How to Create Recursive Dimension Hierarchy

    Hi all
    i will be glade if any body know how i can create Recursive Dimension Hierarchy
    where the number of levels is varibel.
    like the Account DIM or manager Dim
    eg
    i have the follwing table
    EmpId Name -- MangerID
    where Manager id is a forign key to Empid
    regards,

    Hi
    Have a look at my blog post here: http://www.rossgoodman.com/2007/10/12/dimensionally-modelling-a-recursive-hierarchy/
    Hope that helps.
    Ross
    http://www.RossGoodman.com

  • How to create new approval hierarchy

    Dear Experts, I want to know if we can create a new approval hierarchy.
    I know that there is a existing seeded hierarchy. We create new process and it goes for review and finally it gets approved. But this would happen according to roles assigned to the users and that to for only two steps one is the reviewer and other is the approver, but i want that there be 2 reviewer and 3 approver, than how can i assign any further roles for the same process to be to be reviewed and approved by more people.
    1) Can we create new approval hierarchy.if yes then how?
    2) what will be there roles assigned to them?
    3) if it can be done by rules , than what is the scripts for the same.?
    4) If it can be done with perspective hierarchy then how to confirgure and what roles to assign?
    Please help me with the above problem.
    Regards,
    Prince

    This can be done, but it will require work using Flow Rules and perhaps Form Rules. This is a complex setup you're looking for, and I would recommend seeking a professional implementer to assist you. People like Oracle Consulting for GRC is available and have had success in these type of setups.

  • How to create only heading hierarchy

    Hi,
    i created hierarchy for the heading level, but it is getting hierarchy at data level also,
    How can i get hierarchy only at heading level and not at data level.
    Can anyone suggest.
    Thanks

    Do you know that drill down is happens based on the keys specified in dimension, by keys we get the next level not by heading.
    If you want to give a try then unset interaction at Value Interaction and see how it works.
    Option is to hide data ;)

  • How to create a nested hierarchy of layers in Acrobat X

    After researching on line for a few days it appears that AutoCAD 2012 64 bit no longer supports PDFMaker.  In the old PDFMaker it would appear that I could select AutoCAD layers to make a layer groups or nested hierarchy.  I want create something like the first page of this http://floridadisaster.org/publicmapping/HELP.pdf  Multiple groups with nested sublayers to several levels.  With no luck on the exporting end I wonder if there is an Adobe product that can do this.  Illustrator creates the same structure and then only exports the top layer.  InDesign doesn't allow for layer groups or nested layers unless it has the DTP plugin, but then it only exports the top level layers.  Any ideas?  I have yet to find a product other than ArcGIS which is overkill for just the creation of a layer/sublayer hiearchy and expensive.
    Thanks,
    Josh

    Actually, the "tree" you see on the right panel isn't a layers tree at all. OCGs (aka "layers") in a PDF file are in a simple 1-level stack, but you can define groups of layers, which Acrobat displays using the tree style. While there's no grouping or ungrouping tool in the user interface in Acrobat, you can do it via JavaScript by writing arrays of arrays into the doc.OCGOrder object. To quote the Acrobat SDK:
    The simplest order array is a flat array of OCG objects. In this case, the listed OCGs are displayed in the UI as a flat list in the same order. If a subarray is present in the order array and the first element of the array is a string, the string will be listed with the rest of the array nested underneath it. If the first element of the array is not a string, the entire array will appear nested underneath the OCG preceding the subarray.

  • How to create a tree view to show hierarchy

    Hi all,
    i am new in plugin development.i need help in creating a tree view to show hierarchy.i gone through sdk\paneltreeview example.but not getting clear idea how to create child node.and how to display it..i want to create a simple tree view which displays my custom data as root\child in hierarchy as i want.
    thanks..

    I did this in CS3 a few weeks ago...
    1. subclass NodeIDClass to create your node id class.
    2. subclass ITreeViewHierarchyAdapter to create the adapter
    3. subclass CTreeViewWidgetMgr
    4. in your .fr file, define two "Class"'es based on kTreeViewWidgetBoss (with Interface IID_ITREEVIEWWIDGETMGR and IID_ITREEVIEWHIERARCHYADAPTER) and kTreeNodeWidgetBoss.
    Btw, I put down "persistentlistui" in my note so I guess I looked at that sample instead of the paneltreeeview.
    Good luck.

  • How to create a hierarchy datasource in BW

    Gurus-
    Here is my requirement.
    I am asked to create a DSO and equivalent datasource for profit center. How to create a datasource for profit center in BW?

    what does ur DSO has to do with the hierarchy? And subject line and the subject are misleading.
    these are some of the std PCA datasources:
    0PROFIT_CTR_0106_HIER       
    0PROFIT_CTR_ATTR                 
    0PROFIT_CTR_TEXT
    0EC_PCA_1                         Profit Center: Transaction Data on Accounts
    0EC_PCA_2                         Profit Center: Statistical key figures
    0EC_PCA_3                         Profit Center: Actual Line Items
    0EC_PCA_4                         Profit Center: Actual Line Items Periodic Transfer

  • How to create a hierarchy in Regional Structure and how to use it

    Hi,
    Please guide me how to create a Political Region Structure hierarchy and how to use it.
    Thanks and Regards

    Hi,
    Thanks for reply please.
    I request you to please copy paste all the possible information here. It will be a great help.
    I hope you understand why we can not provide our id on this forum.
    Please guide.
    Thanks and Regards
    Edited by: MP Vashishth on May 18, 2009 7:14 AM

  • How to create a hierarchy info source

    Please give a step by step procrdure of how to create a hierarchy info source

    Hi,
    Check this blog:
    Hierarchy Upload from Flat files
    Bye
    Dinesh

  • How to create hierarchy across more than one dimesion

    Hi experts,
     How to create hierarchy on more than one dimension in SSAS.please guide me.
    Thanks

    Hi ,
    This is not Possible without making changes in the cube design .i.e;
    Using Join for have to create one dimension with all attributes that you require in dimension .
    Lets say you have
    Dim1
     att1
     att2
     att3
    Dim2
      F1
      F2
    You need Hierarchy as below;
    Hier
     att1
     att3
     F2
    1. Add one Table in DSV using Join between both the tables.
    2.Create Dimension using this newly added table.
    3. Create hierarchy
    https://www.simple-talk.com/sql/reporting-services/implementing-user-defined-hierarchies-in-sql-server-analysis-services/
    Thanks
    Please Mark This As Answer or vote for Helpful Post if this helps you to solve your question/problem. http://techequation.com

Maybe you are looking for

  • Operations from PCR in simple english.

    NUM= BWGRL NUM= PLANS NUM?0 ZERO= N GCY X112 ADDWT above are some of the operations from PCR  X012 Calculate valuation bases for alternative payment as we know, there is a logical meaning for all the operations listed above however there must be a si

  • Video Stall after 5.1 or 5.1.1 update on ATV 3

    Twice I thank the posters to this forum for giving me the information to "roll back" to 5.0.2.  Twice I have upgraded and twice videos (Youtube and Netflx) stall after 1-2 minutes following the 5.1.? update.  Restarting the modem, router, and ATV doe

  • Unable to create shared folder when creating distribution list

    Hi, I am trying to create a new Distribution List in ECC  using T-code SO23. The system is not allowing me to create a new Shared Folder (step in creating the DL). Instead, I get a message saying 'Folder does not exist' (message code :SO 005) I do no

  • Sort YouTube videos by date?

    When I look at videos from an account that I subscribe to, is there any way to change the sort order?  They seem to be sorted in descending order by number of views.  I would like to sort them in decending order by upload date so that I can easily fi

  • Need help creating large SQL query

    I am trying collect the sum of records that have a cancelled event prior to the Arrive event. The solution needs to be within the Sum function. Any ideas would be helpful The structure of the table is as follows 1. Record_Num(primary): varchar 2. Eve