SELECT, hierarchical queries and JOIN

Hi everyone,
I have a small SELECT statement but I can't find an easy solution.
Look at this situation:
drop table departments;
CREATE TABLE departments
  dpt_id NUMBER(10) UNIQUE,
  dpt_name VARCHAR2(100),
  dpt_parent_id NUMBER(10)
TRUNCATE table departments;
INSERT INTO departments VALUES(1, 'Company', null);
INSERT INTO departments VALUES(2, 'HR', 1);
INSERT INTO departments VALUES(3, 'SALES', 1);
INSERT INTO departments VALUES(4, 'IT', 1);
INSERT INTO departments VALUES(222, 'Helpdesk', 4);
INSERT INTO departments VALUES(223, 'French Speaking', 222);
INSERT INTO departments VALUES(224, 'Another level', 223);
INSERT INTO departments VALUES(5, 'LEGAL', 1);
INSERT INTO departments VALUES(66, 'Recruitment', 2);
INSERT INTO departments VALUES(33, 'Logistics', 2);
INSERT INTO departments VALUES(39, 'Fleet management', 33);
INSERT INTO departments VALUES(31, 'Local Sales', 3);
INSERT INTO departments VALUES(60, 'European Sales', 3);
INSERT INTO departments VALUES(61, 'Germany', 60);
INSERT INTO departments VALUES(62, 'France', 60);
INSERT INTO departments VALUES(620, 'Paris', 62);
INSERT INTO departments VALUES(621, 'Marseilles', 62);
INSERT INTO departments VALUES(38, 'American Sales', 3);
INSERT INTO departments VALUES(34, 'Asian Sales', 3);
CREATE table persons
  person_id NUMBER(10) UNIQUE,
  person_name VARCHAR2(100),
  person_dpt_id NUMBER(10)
truncate table persons;
INSERT INTO persons VALUES(1, 'Jim', 2);
INSERT INTO persons VALUES(2, 'Jack', 621);
INSERT INTO persons VALUES(3, 'John', 620);
INSERT INTO persons VALUES(4, 'John', 224);
INSERT INTO persons VALUES(5, 'Fred', 61);It's a simple hierachy like the one we can find in HR schema. The link between an department and its parent is with parent id. THe following statement build the whole tree:
SELECT dpt_id, level, LPAD(' ', LEVEL-1)|| dpt_name
  FROM departments
START WITH dpt_parent_id IS NULL
CONNECT BY dpt_parent_id = PRIOR dpt_id;As you can see in the script above, I have a few people assigned to these departments. It's also a classic situtation...
I would like to have something like this:
WITH temp AS
  SELECT dpt_id, dpt_name, SYS_CONNECT_BY_PATH(dpt_name, '#') as full_path
    FROM departments
   START WITH dpt_parent_id IS NULL
CONNECT BY dpt_parent_id = PRIOR dpt_id
SELECT p.person_name, d.dpt_name, --d.full_path,
       regexp_substr(d.full_path, '[^#]+', 1, 2, 'i') as t1,
       regexp_substr(d.full_path, '[^#]+', 1, 3, 'i') as t2,
       regexp_substr(d.full_path, '[^#]+', 1, 4, 'i') as t3,
       regexp_substr(d.full_path, '[^#]+', 1, 5, 'i') as t4
  FROM persons p
  JOIN temp d ON d.dpt_id = p.person_dpt_id;This is the exact output I want, but I wonder... Is it possible to do it without the factored sub-query? It's nice and works fine but I had to precompute the whole path to split it again. I mean, this should be possible in one step. Any suggestion?
I'm using Oracle 10g
Thanks,

Hi,
user13117585 wrote:
... But sometimes, I just find the statements difficult for what they do. For example, my previous one. I have a person, and I want to see his department and the path in the tree.Actually, you want more than that; you want to parse the path, and display each #-delimited part in a separate column. If you didn't want that, then you could do away with the 4 REGEXP_SUBSTR calls, like this:
WITH temp AS
  SELECT dpt_id, dpt_name
  ,       SUBSTR ( REPLACE ( SYS_CONNECT_BY_PATH ( RPAD (dpt_name, 15)     -- Using 15 just for demo
           , 16
           )     as full_path
    FROM departments
   START WITH dpt_parent_id IS NULL
CONNECT BY dpt_parent_id = PRIOR dpt_id
SELECT p.person_name, d.dpt_name, d.full_path
  FROM persons p
  JOIN temp d ON d.dpt_id = p.person_dpt_id;Output:
PERSON_N DPT_NAME      FULL_PATH
Jim      HR            HR
Fred     Germany       SALES          European Sales Germany
John     Paris         SALES          European Sales France         Paris
Jack     Marseilles    SALES          European Sales France         Marseilles
John     Another level IT             Helpdesk       French SpeakingAnother levelAs you can see, full_path is one giant column, but it's formatted to look like 4 separate columns, forresponding to your original t1, t2, t3 and t4. I limited the output to 15 characters, just for debugging and posting purposes. You can use any number of characters you like.
It's too complex for this simple thing.It would be nice if there was something simpler that did exactly what you wanted, but I'm not sure it's reasonable to expect it in every case. I asked a lot of questions in my first message, but I'm not sure you've tried to answer any of them, so I'm not sure why you're unhappy with the query you posted. I can think of lots of ways to change the query, but I have no way of telling if you would like them any better than what you already have.
And hopefully, I know where to start in the hierarchy and I know where to stop. If I had to show all the levels and have one column by level dynamically, I'd be stuck. Sorry, I don't understand this part.
Are you saying that it seems inefficient to generate the entire tree, when perhaps few of the nodes will have have matches in the persons table? If so, you can invert the whole query. Instead of doing the CONNECT BY first and then joining, do the join first and then the CONNECT BY. Instead of doing a top-down CONNECT BY, where you start with the parentless nodes (whether or not you'll ultimately need them) and then find their descendants, do a bottom-up CONNECT BY, where you start with the nodes you know you'll need, and then find their ancestors.
I just find it difficult for such a simple need. Again, there are lots of things that could be done. If you won't say what you want, that makes it hard for me to tell you how to get it. All that I've picked up for sure is that you don't like doing a sub-query. That's unfortunate, because sub-queries are so basic. They have very important been since Oracle 8.1, and they don't seem to be going away. Quite the opposite, in fact. You need sub-queries for all kinds of things, not just CONNECT BY. To give just a couple of examples, they're the only thing that make analytic functions really useful, and they simplfy chasm traps (basically, multiple 1-to-many relationships on the same table) considerably. I'm sorry if you don't lke sub-queries, but I don't see how you can work in this field and not use them.
Edited by: Frank Kulash on Nov 15, 2011 3:18 PM
Revised query

Similar Messages

  • Hierarchal queries and USER_DEPENDENCIES

    I'm new to Hierarchal queries; I have a Hierarchal query on USER_DEPENDENCIES that does not work and gives an error
    'TSPKG_ES' is a package the works; I'm trying to do query to see what is calls
    SELECT LEVEL, D.*
    FROM DBA_DEPENDENCIES D
    START WITH D.name = 'TSPKG_ES'
    CONNECT BY PRIOR D.name = D.referenced_name
    Result = ORA-00600: internal error code, arguments: [sorsikbeg_1], [5], [0] ,[],[],[],[],[]
    SELECT LEVEL, D.*
    FROM DBA_DEPENDENCIES D
    START WITH D.name = 'DATATESTSPKG_ES'
    CONNECT BY PRIOR D.referenced_name = D.name
    Result = ORA=0143: CONNECT BY loop in user data

    OS = Microsoft Windows XP V2002 Service Pack 3
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    "CORE     10.2.0.4.0     Production"
    TNS for 64-bit Windows: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production

  • Hierarchical queries and referential constraints

    Experts,
    What is the rationale for having a referential integrity constraint on a table that has rows bound by hierarchical relationships ?? The hierarchical relationship ensures that each row is referencing another in the same table via the PRIOR clause. If I add a foreign key relationship to these columns , does it make any sense ??/
    -Rekha

    but you can use a hierarchical query to display constraints in a tree !
    SQL> create table t1 (a number primary key);
    Table created.
    SQL> create table t2 (b number primary key, a number references t1(a));
    Table created.
    SQL> create table t3 (c number primary key, b number references t2(b));
    Table created.
    SQL> create table t4 (d number primary key, a number references t1(a));
    Table created.
    SQL> create table t5 (e number primary key, f number references t5(e));
    Table created.
    SQL> select sys_connect_by_path(p.table_name,':')||':'||r.table_name p
    from all_constraints p
        join all_constraints r
        on (p.constraint_name = r.r_constraint_name and p.owner = r.r_owner)
    where CONNECT_BY_ISLEAF = 1
    connect by nocycle prior r.table_name = p.table_name
    start with p.table_name not in (select r.table_name from all_constraints p join
    all_constraints r on (p.constraint_name = r.r_constraint_name and
    p.owner = r.r_owner and p.table_name != r.table_name) );
    :DEPT:EMP
    :T1:T4
    :T1:T2:T3
    :T5:T5

  • Select with transposition and join

    Hi Guys!
    I'm using Oracle 9i and I'm facing the following problem:
    My table looks like this:
    Stripe
    Unit
    Value
    1
    1
    a1
    1
    2
    a2
    1
    3
    a3
    2
    1
    b1
    2
    2
    b2
    2
    3
    b3
    2
    4
    b4
    4
    1
    c1
    4
    2
    c2
    4
    3
    c3
    4
    4
    c4
    4
    5
    c5
    My result should look like this:
    Unit
    Stripe1 Value
    Stripe2 Value
    Stripe3 Value
    Stripe4 Value
    1
    a1
    b1
    c1
    2
    a2
    b2
    c2
    3
    a3
    b3
    c3
    4
    b4
    c4
    5
    c5
    I tried it with one select for each stripe and full joins, but in this example I would only see the first 3 units....
    Any ideas?

    Another way, but only if your on database version 11gR1 and onwards, is to use the PIVOT operator:
    SQL> -- generating sample date:
    SQL> with t as (
      2  select 1 stripe, 1 unit, 'a1' value from dual union
      3  select 1, 2, 'a2' from dual union
      4  select 1, 3, 'a3' from dual union
      5  select 2, 1, 'b1' from dual union
      6  select 2, 2, 'b2' from dual union
      7  select 2, 3, 'b3' from dual union
      8  select 2, 4, 'b4' from dual union
      9  select 4, 1, 'c1' from dual union
    10  select 4, 2, 'c2' from dual union
    11  select 4, 3, 'c3' from dual union
    12  select 4, 4, 'c4' from dual union
    13  select 4, 5, 'c5' from dual
    14  )
    15  --
    16  -- actual query:
    17  --
    18  select *
    19  from ( select unit
    20         ,      stripe
    21         ,      value
    22         from   t
    23       )
    24  pivot (max(value) for (stripe) in ( 1 as stripe1value
    25                                    , 2 as stripe2value
    26                                    , 3 as stripe3value
    27                                    , 4 as stripe4value
    28                                    )
    29        )
    30  order by unit;
          UNIT ST ST ST ST
             1 a1 b1    c1
             2 a2 b2    c2
             3 a3 b3    c3
             4    b4    c4
             5          c5
    5 rows selected.
    ORACLE-BASE - PIVOT and UNPIVOT Operators in Oracle Database 11g Release 1

  • Transaction codes used to find the table(s), query/queries, and joins.

    Hi.
    I would like to learn how to find out which table(s) to use to create a query(ies), how tables are joined and how to create a query. Besides SQVI and SE16, what other transaction can I access? I would like to use SAP query tools that requires no programming.
    Thank you.

    Hi Minerva ,
    Its not Read-only it is Display Autorization only.It will be comes from role what they assign to ur User ID.
    coming to SQVI is  the simple and best way to create SAP query without any Programming knowledge, but u have to know what tables u have to use to get desire o/p.
    check these
    http://www.sap-img.com/abap/what-is-sap-queries.htm
    http://help.sap.com/saphelp_erp2005vp/helpdata/en/d1/44f2b5c7f411d296080000e82de14a/frameset.htm
    Regards
    Prabhu

  • How to query 2 hierarchical tables and join?

    Hi
    I've been bashing my head against a well to get this to work efficiently in 10g. I can solve the following writing some pretty horrible SQL, but can't figure out how to do it elegantly and optimally.
    We have two hierarchical tables as follows:
    select * from data_categories dac
    dac_code name parent_dac_code
    10 MANAGEMENT
    20 MEDICATION 10
    30 PROCEDURE 10
    40 SURVEY
    50 ASSESS
    60 NATURE 50
    70 OBSERVE 60
    select * from data_elements des
    des_id name parent_des_id dac_code display_seq
    100 DOSE MEDICATION 1
    110 1MG 100 1
    120 2MG 100 2
    130 3MG 100 3
    140 ROUTE MEDICATION 2
    150 ET 140 1
    160 EM 140 2
    170 RESPONSE MEDICATION 3
    180 IMPROVED 170 1
    190 NOCHANGE 170 2
    200 FILED MANAGEMENT 1
    210 INPUT OBSERVE 1
    You'll note:
    1) We have hierarchies in both tables, and a fk from data_elements to data_categories via the dac_code.
    2) The depth of both data_categories and data_elements is unlimited.
    3) There is no single root node record in either table.
    4) The appropriate PK and FK indexes exist.
    We need to write a query that returns the following results:
    root_dac_code parent_dac_code des_level des_id name display_seq
    ASSESS OBSERVE 1 210 INPUT 1
    MANAGEMENT MEDICATION 1 100 DOSE 1
    MANAGEMENT MEDICATION 2 110 1MG 1
    MANAGEMENT MEDICATION 2 120 2MG 2
    MANAGEMENT MEDICATION 2 130 3MG 3
    MANAGEMENT MEDICATION 1 140 ROUTE 1
    MANAGEMENT MEDICATION 2 150 ET 1
    MANAGEMENT MEDICATION 2 160 EM 2
    MANAGEMENT MEDICATION 1 170 RESPONSE 3
    MANAGEMENT MEDICATION 2 180 IMPROVED 1
    MANAGEMENT MEDICATION 2 190 NOCHANGE 2
    MANAGEMENT MANAGEMENT 1 200 FILED 1
    You'll also note we need to return the data in order of the root_dac_code, then parent_dac_code, followed by the display_seq.
    Does anybody know how to write this query in an elegant and optimal manner?
    Many thanks for any help!
    Cheers,
    CM.

    Flakey model.
    Why does data_elements.dac_code appear to refer to data_categories.name rather than data_categories.dac_code?
    You do not appear to be ordering by root_dac_code, parent_dac_code and display_seq (if you were MANAGEMENT/MANAGEMENT would not be at the end). Did you perhaps mean ORDER BY root_dac_code, des_id, display_seq?
    Something like this perhaps?
    Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
    SQL> CREATE TABLE data_categories (
      2    dac_code NUMBER,
      3    name VARCHAR2 (30),
      4    parent_dac_code NUMBER);
    Table created.
    SQL> INSERT INTO data_categories VALUES (10, 'MANAGEMENT', NULL);
    1 row created.
    SQL> INSERT INTO data_categories VALUES (20, 'MEDICATION', 10);
    1 row created.
    SQL> INSERT INTO data_categories VALUES (30, 'PROCEDURE', 10);
    1 row created.
    SQL> INSERT INTO data_categories VALUES (40, 'SURVEY', NULL);
    1 row created.
    SQL> INSERT INTO data_categories VALUES (50, 'ASSESS', NULL);
    1 row created.
    SQL> INSERT INTO data_categories VALUES (60, 'NATURE', 50);
    1 row created.
    SQL> INSERT INTO data_categories VALUES (70, 'OBSERVE', 60);
    1 row created.
    SQL> CREATE TABLE data_elements (
      2    des_id NUMBER,
      3    name VARCHAR2 (30),
      4    parent_des_id NUMBER,
      5    dac_code VARCHAR2 (30),
      6    display_seq NUMBER);
    Table created.
    SQL> INSERT INTO data_elements VALUES (100, 'DOSE', NULL, 'MEDICATION', 1);
    1 row created.
    SQL> INSERT INTO data_elements VALUES (110, '1MG', 100, NULL, 1);
    1 row created.
    SQL> INSERT INTO data_elements VALUES (120, '2MG', 100, NULL, 2);
    1 row created.
    SQL> INSERT INTO data_elements VALUES (130, '3MG', 100, NULL, 3);
    1 row created.
    SQL> INSERT INTO data_elements VALUES (140, 'ROUTE', NULL, 'MEDICATION', 2);
    1 row created.
    SQL> INSERT INTO data_elements VALUES (150, 'ET', 140, NULL, 1);
    1 row created.
    SQL> INSERT INTO data_elements VALUES (160, 'EM', 140, NULL, 2);
    1 row created.
    SQL> INSERT INTO data_elements VALUES (170, 'RESPONSE', NULL, 'MEDICATION', 3);
    1 row created.
    SQL> INSERT INTO data_elements VALUES (180, 'IMPROVED', 170, NULL, 1);
    1 row created.
    SQL> INSERT INTO data_elements VALUES (190, 'NOCHANGE', 170, NULL, 2);
    1 row created.
    SQL> INSERT INTO data_elements VALUES (200, 'FILED', NULL, 'MANAGEMENT', 1);
    1 row created.
    SQL> INSERT INTO data_elements VALUES (210, 'INPUT', NULL, 'OBSERVE', 1);
    1 row created.
    SQL> SELECT dc.root_dac_code, de.parent_dac_code,
      2         de.des_level, de.des_id, de.name, de.display_seq
      3  FROM  (SELECT LEVEL des_level, des_id, name, parent_des_id,
      4                CONNECT_BY_ROOT (dac_code) parent_dac_code, display_seq
      5         FROM   data_elements da
      6         START WITH parent_des_id IS NULL
      7         CONNECT BY PRIOR des_id = parent_des_id) de,
      8        (SELECT CONNECT_BY_ROOT (name) root_dac_code, name dac_code
      9         FROM   data_categories
    10         START WITH parent_dac_code IS NULL
    11         CONNECT BY PRIOR dac_code = parent_dac_code) dc
    12  WHERE  de.parent_dac_code = dc.dac_code
    13  ORDER BY dc.root_dac_code, de.des_id, de.display_seq;
    ROOT_DAC_CODE  PARENT_DAC_CODE   DES_LEVEL DES_ID NAME    
    ASSESS         OBSERVE                   1    210 INPUT   
    MANAGEMENT     MEDICATION                1    100 DOSE    
    MANAGEMENT     MEDICATION                2    110 1MG     
    MANAGEMENT     MEDICATION                2    120 2MG     
    MANAGEMENT     MEDICATION                2    130 3MG     
    MANAGEMENT     MEDICATION                1    140 ROUTE   
    MANAGEMENT     MEDICATION                2    150 ET      
    MANAGEMENT     MEDICATION                2    160 EM      
    MANAGEMENT     MEDICATION                1    170 RESPONSE
    MANAGEMENT     MEDICATION                2    180 IMPROVED
    MANAGEMENT     MEDICATION                2    190 NOCHANGE
    MANAGEMENT     MANAGEMENT                1    200 FILED   
    12 rows selected.
    SQL>

  • Hierarchical queries and nested tables

    Hallo,
    Assume you have the following data structure:
    SQL> desc mgr
    Name Null? Typ
    MGRNO NUMBER
    LASTNAME VARCHAR2(20)
    EMPS EMPTYPE_TAB
    SQL> desc emptype_tab
    emptype_tab TABLE OF EMP_TYPE
    Name Null? Typ
    EMPNO NUMBER
    LASTNAME VARCHAR2(20)
    I would like to select rows in a hierarchical order to get an output like this:
    LAST_NAME EMPNO MGRNO LEVEL
    King 100 1
    Cambrault 148 100 2
    Bates 172 148 3
    ..but i have absolutely no clue how to use the hierarchical query clause with a nested table.
    can anybody help me?

    scott@ORA92> CREATE OR REPLACE TYPE emp_type AS OBJECT
      2    (empno      NUMBER,
      3       lastname VARCHAR2(20))
      4  /
    Type created.
    scott@ORA92> CREATE OR REPLACE TYPE emptype_tab AS TABLE OF emp_type
      2  /
    Type created.
    scott@ORA92> CREATE TABLE mgr
      2    (MGRNO      NUMBER,
      3       LASTNAME VARCHAR2(20),
      4       EMPS      EMPTYPE_TAB)
      5    NESTED TABLE emps STORE AS emps_nt
      6  /
    Table created.
    scott@ORA92> INSERT INTO mgr VALUES (NULL, NULL, emptype_tab (emp_type (100, 'King')))
      2  /
    1 row created.
    scott@ORA92> INSERT INTO mgr VALUES (100, 'King', emptype_tab (emp_type (148, 'Cambrault')))
      2  /
    1 row created.
    scott@ORA92> INSERT INTO mgr VALUES (148, 'Cambrault', emptype_tab (emp_type (172, 'Bates')))
      2  /
    1 row created.
    scott@ORA92> SELECT * FROM mgr
      2  /
         MGRNO LASTNAME
    EMPS(EMPNO, LASTNAME)
    EMPTYPE_TAB(EMP_TYPE(100, 'King'))
           100 King
    EMPTYPE_TAB(EMP_TYPE(148, 'Cambrault'))
           148 Cambrault
    EMPTYPE_TAB(EMP_TYPE(172, 'Bates'))
    scott@ORA92> SELECT m.mgrno, m.lastname as mgr, e.empno, e.lastname as emp
      2  FROM   mgr m, TABLE (emps) e
      3  /
         MGRNO MGR                       EMPNO EMP
                                           100 King
           100 King                        148 Cambrault
           148 Cambrault                   172 Bates
    scott@ORA92> SELECT lastname, empno, mgrno, LEVEL
      2  FROM   (SELECT m.mgrno, e.lastname, e.empno
      3            FROM   mgr m, TABLE (emps) e)
      4  START  WITH mgrno IS NULL
      5  CONNECT BY PRIOR empno = mgrno
      6  /
    LASTNAME                  EMPNO      MGRNO      LEVEL
    King                        100                     1
    Cambrault                   148        100          2
    Bates                       172        148          3
    scott@ORA92>

  • Hierarchical Queries help me

    hi,
    What is the usage of 'Connect' , 'Prior' in hierarchical queries and
    what does it mean??

    http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14200/queries003.htm
    Cheers
    Sarma.

  • Activation of BW Production Objects and Transport of Queries and Work books

    Hi,
    I have successfully transported 0FIGL_1 InfoCube (only in Data Flow Before) from BW DEV to BW Production...
    But In BW Production This Cube and InfoSources and Update rules and InfoObects are all in inactive...
    What to do?..
    Please tell me step by step procedure.....
    and also suggest me on how to transport Queries and work books related to My 0FIGL_1 Cube...
    Please tell me all step by step procedure...
    Help will be greatly appreciated..
    This is very urgent
    Thanks in advance...

    Hi,
    May be you are telling is correct but i am unable to follow..
    Please correct if my understanding is wrong....
    1. I have Created one BEx Truck Request...it is not Released so far..So, it is there in SE09 of BW DEV
    2. Selected Queried and work books --- Grouping --- Only necessary objects -- Collection mode -- automatic...(Default all queries and workbooks selected as check box)
    3. Click Transport truck (Which is beside of Grouping Option)..
    4. Created one request and then released... But not imported into BW Production..
    5. Now I have modified all the queried (Change text)
    6. RSA1 -- Transport connection -- Selected modified queried...
    7. Grouping only necessary objects and collected mode --automatic...
    8. Selected modified queries and dragged into right side...
    My question here is they are not checked check box under transport?...shall i check it?
    Shall i release Old BEx Request? and then before transporting these new modified queries Create another BEx Request?
    or else..
    Create new request for modified Queries? and then transport?
    Now the situation is i have already created transport request for modified queries..What to do? shall i release them also?...
    Pls suggest me....

  • Self join vs Hierarchical Queries

    Hi,
    please tel me which one 1 should use ?
    i have to get simple manger's employ list, should i use self join or hierarchical queries(CONNECT BY and prior)?
    yours sincerely

    Hi,
    944768 wrote:
    Hi,
    please tel me which one 1 should use ?
    i have to get simple manger's employ list, should i use self join or hierarchical queries(CONNECT BY and prior)?It depends on your data and your requirements.
    Whenever you have a question, please post a little sample data (CREATE TABLE and INSERT statements) for all the tables involved, so the people who want to help you can re-create the problem and test their ideas. Also post the results you want from that data, and an explanation of how you get those results from that data.
    Explain, using specific examples, how you get those results from that data.
    If you can show what the problem is using commonly available tables (suc as scott.emp, which has a 4-level hierarchy) then you don't have ot post any sample data, just the results and the explanation.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}
    If your hierarchy consists only of 2 levels, then a self-join will probably be more efficient, simpler to code, and easier to maintain.
    If you don't know how many levels are in the hierarchy, then self-join isn't an option. Use CONNECT BY or, if you have Oracle 11.2, a recursive WITH clause.
    If you have a fixed number of levels (or an upper bound) greater than 2, then CONNECT BY (or a recursive WITH clause) will probably be best.

  • CMIS JOIN Queries and UCM

    HI Guys,
    Quick question. Does the UCM CMIS integration support JOINs in the query syntax ?
    I am trying to construct a query whereby I need to see the Content Items where the Document Title is repeated in multiple folders. The use case is that we want enforce unique names for each content item and we want to highlight those documents that have the same name.
    Seems like constructing a CMIS query with JOINS across folders by Content Name seems like a good fit but just wanted to check that will UCM support such a construct before I start developing.
    Cheers
    Sanjay

    I just read this in the CMIS documentation:
    "CMIS queries return a Result Set where each Entry object will contain only the properties that were specified in the query. As the Content Management REST Service does not support JOINs in queries, each result entry will represent properties from a single node. Common searches use a query like "SELECT * FROM …"."
    "When searching documents (select * from cmis:document), it is not possible to limit the search to more than just a single content type; for example, this is not supported: "select * from IDC:MyProfile, IDC:AnotherProfile" because it has multiple explicit content types and JOINS are not supported."
    So i'm afraid it will not be possible...
    source of the doucment: http://download.oracle.com/docs/cd/E17904_01/doc.1111/e15813/toc.htm

  • Select Distinct and join in ODI

    Hi,
    I have following task to perform: I am loading metadata into Planning dimension from Oracle database. I have two tables
    1. "Sales"
    Columns: Name, Number, Value
    Sample Data:
    Product 1, 10, 200
    Product 2, 30, 100,
    Product 1, 15, 500
    2. P&R
    Columns:
    Name, Alias
    Product 1, SampleSoda1
    Product 2, SampleSoda2,
    Resource 1, CanForSoda,
    Resource 2, CO2
    What I need to do is: I have to select name and alias from second table of all products that were sold.
    So I need to select distinct Name from Table 1, naxt join it with Table 2 (so I have Name and Alias) and load it to planning.
    I am a little confused how to do it.
    Any help would be great!
    Best regards,
    Greg

    Hi Greg,
    What you can do is either :
    - Create a yellow interface with your table Sales as source. Map the name column directly in the target. In the flow tab, click on your target and select "Distinct rows".
    - Create a second interface, with your first interface as source. Select the "Use Temporary Interface as Derived Table (Sub-Select)" checkbox.
    - Add your second datastore and join it. Or you can use a lookup table.
    OR
    - Create an interface with Sales and P&R as source (or set P&R as a lookup table).
    - Go on the flow tab and select "Distinct rows".
    If you've a lot a data in the first table, I would go for the first solution.
    Hope it helps.
    Regards,
    JeromeFr
    Edited by: JeromeFr on Feb 14, 2013 9:52 AM
    To be more clear in the first step of solution 1

  • Absolute dynamic select query with dynamic join and where

    Has anyone ever tried creating an absolutely dynamic SELECT query with dynamic Join and Where conditions.
    I have a requirement of creating such a query in an Utility Class, and i have written the code. But its throwing my sysntax errors.
    Please let me know where am I going wrong OR is it really possible to create such a dynamic Query??
        SELECT (FIELDS) INTO TABLE IT_TABLES
          FROM ( (ME->TABLE1)  inner join ( me->table2 )
          on ( on_condition ) )
          WHERE (me->where_fields).
    Ags.

    It worked for me in a following way:
    select * into corresponding fields of table <result_table>
            from (join_string)
            where (l_where).
    Where the contents of join_string were dynamically build using concatenation. So it will be something like
    concatenate ME->TABLE1 'as a INNER JOIN' me->table2 'as b ON (' into join_string separated by space.
    <...>
    add here matching/reference colums, something like
    concatenate 'a~' me->TABLE1_JOIN_COL into temp1.
    concatenate 'b~' me->TABLE2_JOIN_COL into temp2.
    concatenate join_string temp1 '=' temp2 into join_string separated by space.
    <...>
    concatenate join_string ')' into join_string separated by space.
    And then use similar approach for l_where variable.

  • Select and join one month record

    I receive a request from my customer . He want generate a total sales record for a month and those data stored in daily sales table and customer table.
    tblcustomer-20140101
    tblcustomer-20140102
    tblcustomer-20140103
    tblcustomer-20141231
    tblsales-20140101
    tblsales-20140102
    tblsales-20140103
    tblsales-20141231
    is there anyway when user select month name from application(ex: April), it will choose all april record and join it together?

    Hi kjleong,
    Generally to say, it is not a good practice to store the same entity data individually for each day, there are many shortages, such as the problem you posted in this thread. You can put all of them into one table and tag them with a DATE column. Anyway
    in this case, to achieve your requirement, you may refer the below stored procedure(SP).
    CREATE PROC ProcGetSales
    @Year VARCHAR(20),
    @Month VARCHAR(20)
    AS
    DECLARE @Date DATE;
    DECLARE @Days INT;
    DECLARE @SqlStr NVARCHAR(MAX);
    SET @Date = @Year+'-'+@Month+'-01';
    SET @Days = DATEDIFF(DAY,@Date,DATEADD(MM,1,@Date)); --get the days of the specific month
    create a temp table
    CREATE TABLE #Temp
    col1 int --you should put the columns after join in your real envrioment here
    table join statement, put the join result into a temp table
    I dont know the columns so I use * here and the join condition is just based on assumption
    you should modify the statement basing on your real environment
    SET @SqlStr= 'INSERT INTO #Temp SELECT * FROM [tblcustomer-WhichDay] tc JOIN [tblsales-WhichDay] ts ON tc.customerID = ts.customerID';
    DECLARE @Counter INT = 1;
    WHILE @Counter <= @Days --loop the tables named after the specific month
    BEGIN
    DECLARE @Sql NVARCHAR(MAX) = REPLACE(@SqlStr,'WhichDay',CONVERT(VARCHAR(8),CAST(@Year+'-'+@Month+'-'+LTRIM(STR(@Counter)) AS DATE),112));
    EXEC sp_executesql @Sql;
    SET @Counter = @Counter+1;
    END
    SELECT * FROM #TEMP
    The SP is not ready to use, you have to make some modification basing on your real environment before it works.
    If you have any question, feel free to let me know.
    Best regards,
    Eric Zhang
    If you have any feedback on our support, please click
    here.

  • How can I edit imported audio track? After selecting and deleting region and joining remaining parts, it keeps playing the track with the deleted part! What am I doing wrong?

    How can I edit imported audio track? After selecting and deleting region, and joining remaining parts, it keeps playing the track with the deleted region!
    What am I doing wrong?

    After selecting and deleting region, and joining remaining parts, it keeps playing the track with the deleted region!
    What am I doing wrong?
    How exactly are you doing this?
    When I cut out a part of an audio region, then drag the remaining parts together, so they are touching, the track will skip the cut out section when playing the file.  Also, if I select the remaining parts of the region and use the command "Edit > join regions". This will create a new audio file with the cut out part deleted.
    You should see this prompt, when you are joining the regions:

Maybe you are looking for

  • Email and text messae notifications

    I purchase a ringtone.  It only shows up in the ringtones for the phone.  I would like to use it for email and text notification. How do I set it up?

  • Freight Line Item in MIRO

    Dear All, I have done the GR for 2 times, against the same PO which includes Freight Charges also. When i try to post the invoice thro' MIRO, I am getting 3 line items. 2 for the Materials & only 1 line item for the Freight charges which includes cha

  • Itunes not loading correctly

    Loading the latest version of iTunes has resulted in an absolute disaster. HP Pavillion. Microsoft Windows 7 Home Premium Edition (64-bit), Norton Anti-Virus Since I upgraded to iTunes 11.0.1.12 it has been an unmitigated disaster. I have an iPad, an

  • HT204291 Airplay w iPad , Black screen on TV worked , fine yesterday?

    Will not mirror tv screen goes black when mirroring is turned. Work fine yesterday.

  • I need help deleting "all records associated with my domain name"

    Hello, I'm having problemsthe same exact problem as Daren... setting up my site to go live. Here's what I've done so far: 1) built the site and pushed it live 2) upgraded the site 3) set up a GoDaddy domain name 4) set up the servers on GoDaddy 5) se