Is it possible without a self join

Hi oracle guru
I have this query result expected is same but without using a join
with t as
( select 1 job_id,'First a' mess,to_date('18:08:2010 13:54:21','DD-MM-YYYY HH24:MI:SS) jtime from dual union all
select 2 ,'First b' ,to_date('18:08:2010 13:54:22','DD-MM-YYYY HH24:MI:SS) from dual union all
select 3 ,'Last a' ,to_date('18:08:2010 13:54:25','DD-MM-YYYY HH24:MI:SS) from dual union all
select 4 ,'Last b' ,to_date('18:08:2010 13:54:27','DD-MM-YYYY HH24:MI:SS) from dua )
select a.*,b.jtime from t a , t b where a.job_id b.job_id and trim(substr(a.mess,6,length(a.mess))) = trim(substr(b.mess,5,length(b.mess)))
Thanks
RP

Hi
When posting code on the forum, put {noformat}{noformat} (with the curly brackets and the word code in lowercase) above and below your code like this...
{noformat}{noformat}
SELECT *
FROM emp
{noformat}{noformat}
It will then appear like this, preserving formatting...SELECT *
FROM emp
Also, your example had about 8 errors in it. Please ensure that it at least runs before posting it. I think you actually meant this...WITH t
AS (SELECT 1 job_id,
'First a' mess,
TO_DATE('18:08:2010 13:54:21', 'DD-MM-YYYY HH24:MI:SS')
jtime
FROM DUAL
UNION ALL
SELECT 2,
' First b',
TO_DATE('18:08:2010 13:54:22', 'DD-MM-YYYY HH24:MI:SS')
FROM DUAL
UNION ALL
SELECT 3,
'Last a',
TO_DATE('18:08:2010 13:54:25', 'DD-MM-YYYY HH24:MI:SS')
FROM DUAL
UNION ALL
SELECT 4,
' Last b',
TO_DATE('18:08:2010 13:54:27', 'DD-MM-YYYY HH24:MI:SS')
FROM dual)
SELECT a.*, b.jtime
FROM t a, t b
WHERE a.job_id = b.job_id
AND TRIM(SUBSTR(a.mess, 6, LENGTH(a.mess))) =
TRIM(SUBSTR(b.mess, 5, LENGTH(b.mess)))
Cheers
Ben                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • How to Avoid Self Join

    Hi
    Assume I have following table
    Id Code
    1 aa
    1 bb
    1 cc
    2 bb
    2 cc
    The records will be grouped by Id. I want to find out group containing code say 'aa' and 'bb'.
    Is it possible to obtain the desired result in a single query without using Self join?
    Regards
    ~Pravin

    This is a little clumsy....Anyway try it:
    WITH t AS
    (SELECT 1 id,'aa' code FROM dual
    UNION ALL
    SELECT 1,'bb' FROM dual
    UNION ALL
    SELECT 1,'cc' FROM dual
    UNION ALL
    SELECT 2,'bb' FROM dual
    UNION ALL
    SELECT 2,'cc' FROM dual)
    SELECT id FROM t
    WHERE code IN('aa', 'bb')
    GROUP BY id HAVING COUNT(*) = 2;

  • Is it possible without a join

    Hi oracle guru
    I have this query result expected is same but without using a join
    with t as
    ( select 1 job_id,'First a' mess,to_date('18:08:2010 13:54:21','DD-MM-YYYY HH24:MI:SS) jtime from dual union all
    select 2 ,'First b' ,to_date('18:08:2010 13:54:22','DD-MM-YYYY HH24:MI:SS) from dual union all
    select 3 ,'Last a' ,to_date('18:08:2010 13:54:25','DD-MM-YYYY HH24:MI:SS) from dual union all
    select 4 ,'Last b' ,to_date('18:08:2010 13:54:27','DD-MM-YYYY HH24:MI:SS) from dua )
    select a.*,b.jtime from t a , t b where a.job_id <> b.job_id and trim(substr(a.mess,6,length(a.mess))) = trim(substr(b.mess,5,length(b.mess)))
    Thanks
    RP

    Hi oracle guru
    I have this query result expected is same but without using a join
    with t as
    ( select 1 job_id,'First a' mess,to_date('18:08:2010 13:54:21','DD-MM-YYYY HH24:MI:SS) jtime from dual union all
    select 2 ,'First b' ,to_date('18:08:2010 13:54:22','DD-MM-YYYY HH24:MI:SS) from dual union all
    select 3 ,'Last a' ,to_date('18:08:2010 13:54:25','DD-MM-YYYY HH24:MI:SS) from dual union all
    select 4 ,'Last b' ,to_date('18:08:2010 13:54:27','DD-MM-YYYY HH24:MI:SS) from dua )
    select a.*,b.jtime from t a , t b where a.job_id <> b.job_id and trim(substr(a.mess,6,length(a.mess))) = trim(substr(b.mess,5,length(b.mess)))
    Thanks
    RP

  • Oracle query with out using self join

    hi friends,
    i have one table for exeample PERSTATUS
    pk/fK STUDENT NUMBER SUBJECT MARKS STATUS
    1 ACCOUNTS 15 RED
    1 MATHS 35 YELLOW
    1 SCINECE 45 GREEN
    2 ACCOUNTS 55 BROWN
    2 MATHS 35 YELLOW
    2 SCINECE 45 GREEN
    3 ACCOUNTS 15 RED
    3 MATHS 35 YELLOW
    3 SCINECE 45 GREEN
    i want students how status is both red and yellow so i am using self join
    i want students status is both red and yellow so i am using self join
    SELECT PS.STUDENTNUMBER,PS.STATUS,PS.STATUS1 FROM PERSTATUS PS ,PERSTATUS PS1
    WHERE PS.STUDENTNUMBER-PS1.STUDENTNUMER
    PS.STATUS='RED' AND PS1.STAUTS='YELLOW'
    i want students status is both RD and YELLOW AND GREEN so i am using self join( two self joinS}
    SELECT PS.STUDENTNUMBER,PS.STATUS,PS.STATUS,PS2.STATUS FROM PERSTATUS PS ,PERSTATUS PS1,PERSTATUS PS2
    WHERE PS.STUDENTNUMBER-PS1.STUDENTNUMER AND PS.STUDENTNUMBER-PS2.STUDENTNUMBER
    PS.STATUS='RED' AND PS1.STAUTS='YELLOW' AND PS2.STAUTUS='GREEN'
    if i require MORE STATUS then more self joins required, is there any alternative to achive this
    and if results comes in multiple rows are accepted (since with the above query result will come in single row)
    i tried to use group by (studentnumber,status) with status='red' and status='yellow'
    but it is not possible could you povidet he solution

    Hi,
    Whenever you have a problem, please post CREATE TABLE and INSERT statements for your sample data, and the exact results you want from that data. Explain how you get those results from that data.
    See the forum FAQ {message:id=9360002}
    Here's an example of how to post the sample data:
    CREATE TABLE     perstatus
    (       studentnumber     NUMBER
    ,     subject          VARCHAR2 (10)
    ,     marks          NUMBER
    ,     status          VARCHAR2 (10)
    INSERT INTO perstatus (studentnumber, subject,    marks, status)
           VALUES           (1,           'ACCOUNTS', 15,       'RED');
    INSERT INTO perstatus (studentnumber, subject  ,  marks, status)
           VALUES           (1,           'MATHS',        35,       'YELLOW');
    INSERT INTO perstatus (studentnumber, subject,    marks, status)
           VALUES           (1,           'SCINECE',  45,       'GREEN');
    INSERT INTO perstatus (studentnumber, subject,    marks, status)
           VALUES           (2,           'ACCOUNTS', 55,       'BROWN');
    INSERT INTO perstatus (studentnumber, subject  ,  marks, status)
           VALUES           (2,           'MATHS',        35,       'YELLOW');
    INSERT INTO perstatus (studentnumber, subject,    marks, status)
           VALUES           (2,           'SCINECE',  45,       'GREEN');
    INSERT INTO perstatus (studentnumber, subject,    marks, status)
           VALUES           (3,           'ACCOUNTS', 15,       'RED');
    INSERT INTO perstatus (studentnumber, subject  ,  marks, status)
           VALUES           (3,           'MATHS',        35,       'YELLOW');
    INSERT INTO perstatus (studentnumber, subject,    marks, status)
           VALUES           (3,           'SCINECE',  45,       'GREEN');You were on the right track, thinking about GROUP BY. You're interested in something about the whole group of rows that has the same studentnumber. Looking at any individual row won't tell you if that row is part of the group you're interested in or not.
    If you want to see information about the group as a whole, you can do the whole job with GROUP BY. In this case, studnetnumber is the only thing that an entire group has in common. If you wanted to see the studentnumbers that had both RED and YELLOW, that is:
    STUDENTNUMBER
                1
                3here's one way you could do it:
    SELECT       studentnumber
    FROM       perstatus
    WHERE       status     IN ('RED', 'YELLOW')
    GROUP BY  studentnumber
    HAVING       COUNT (DISTINCT status) = 2  -- That is, both RED and YELLOW
    ORDER BY  studentnumber
    ;But say you wanted to see details about individuals in the group; for example, say we want to see all the columns for students that have all 3 of RED, YELLOW and GREEN, like this:
    STUDENTNUMBER SUBJECT         MARKS STATUS
                1 SCINECE            45 GREEN
                1 ACCOUNTS           15 RED
                1 MATHS              35 YELLOW
                3 SCINECE            45 GREEN
                3 ACCOUNTS           15 RED
                3 MATHS              35 YELLOWWe used the aggregate COUNT function earlier, but aggregate functions require collapsing the results down to one row per group.
    However, most of the aggregate functions, like COUNT, have analytic counterparts, that can give the same results without collapsing the result set. Here's one way to get the results above, using the analytic COUNT function:
    WITH     got_cnt          AS
         SELECT  studentnumber, subject, marks, status
         ,     COUNT ( DISTINCT CASE
                                   WHEN  status  IN ('RED', 'YELLOW', 'GREEN')
                             THEN  status
                               END
                    ) OVER (PARTITION BY  studentnumber)     AS cnt
         FROM    perstatus
    SELECT    studentnumber, subject, marks, status
    FROM       got_cnt
    WHERE       cnt  = 3
    ORDER BY  studentnumber
    ,            status
    ;

  • Self join with fact table in Obie 10G

    I am a newbie to obiee.I have a development requirement as follows-
    I need to find supervisors designation with the existing star RPD design. explanation is below
                                                        DIM_Designation(Desig_Wid)
                                                      |(Row_wid)
                                                      |
    DIM_EMPLOYEE--------WORKER_FACT------------DIM_Supervisor
    (Row_Wid)-----------------(Employee_Wid)
                                      (Supervisor_Wid)------------(Row_Wid)
    3 dimension is joined to fact to get employee, his supervisor and designation of employee. now i want to get the supervisor's designation? how is it possible? already employee and supervisor dimension is same W_employee_d table joined with fact as alias DIM_EMPLOYEE and DIM_SUPERVISOR. how to do self join with fact to get supervisor's designation. i do not have any supervisor_desig_wid in fact table. any help is deeply appreciated.

    Yes,Duplicate the fact table create a primary key on the newly fact table alias dimension table.So you can ur data modelling as usual.

  • How to achieve parent-child relationship using self join?

    my table structure is as follows
    parent child name
    -1     1     A1
    1     2     A2
    1     3     A3
    how to achieve the hierarchy model using self join. this can be easily achieved using "connect by prior". but how to achieve the same using self join?

    Hi,
    Yes, that's definitely possible. If you only need to display two levels from the hierarchy, a self-join is a good option. Make it an outer join if you need to show everyone on one level, regardless of whether they have a match on the other level or not; for example, if you want the output:
    child_name     child_id     parent_name     parent_id
    A1          1
    A2          2          A1          1
    A3          3          A1          1It's good that you posted some sample data. Now post the results you want from that data, and your query (what you think is the best attempt you've made so far). If you haven't tried anything so far, then look at some other simple self-join to get ideas.

  • Oracle doc inconsistent on materialize view with union all and self joins

    First of all, I can't seem to create a materialized view containing self-joins AND union all. Is it possible?
    I checked Oracle 9i (my version: PL/SQL Release 9.2.0.4.0 - Production) documentation and I get different answers (or so it seems to me).
    First I saw this: "The COMPATIBILITY parameter must be set to 9.0 if the materialized aggregate view has inline views, outer joins, self joins or grouping sets and FAST REFRESH is specified during creation..."
    Did you see the part about 'self joins' in there? I did and I was pumped because that seems to say that you CAN have 'self joins' (and my compatibility is 9.2...)
    BUT
    In the very same document I also found "Oracle does not allow self-joins in materialized join views." (rage)
    You can see the document I am speaking of here: http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96520/mv.htm#574889
    Whenever I try to create the mview I get the following error. (
    In any caseORA-01446 cannot select ROWID from view with DISTINCT, GROUP BY, etc.

    First of all, I can't seem to create a materialized view containing self-joins AND union all. Is it possible?
    I checked Oracle 9i (my version: PL/SQL Release 9.2.0.4.0 - Production) documentation and I get different answers (or so it seems to me).
    First I saw this: "The COMPATIBILITY parameter must be set to 9.0 if the materialized aggregate view has inline views, outer joins, self joins or grouping sets and FAST REFRESH is specified during creation..."
    Did you see the part about 'self joins' in there? I did and I was pumped because that seems to say that you CAN have 'self joins' (and my compatibility is 9.2...)
    BUT
    In the very same document I also found "Oracle does not allow self-joins in materialized join views." (rage)
    You can see the document I am speaking of here: http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96520/mv.htm#574889
    Whenever I try to create the mview I get the following error. (
    In any caseORA-01446 cannot select ROWID from view with DISTINCT, GROUP BY, etc.

  • Is it Possible to make a join from a single table

    Hi all,
    Is it Possible to make a join from a single table
    Suppose HR_ALL_ORGANIZATION_UNITS table
    can we make a join in the following way
    HR_ALL_ORGANIZATION_UNITS.ORGANIZATION_ID =HR_ALL_ORGANIZATION_UNITS.BUSINESS_GROUP_ID
    Thanks in advance

    Hi
    Yes you can join,
    Like below =- it is called self join -
    Slect a.oersson_id,a.employee_numebr, b.full_name
    form
    hr_all_organization_units a,
    hr_all_organization_units b
    where
    a.person_id = b.person_id and
    sysdate between a.effective_start_date and a.effective_end_date and
    sysdate between b.effective_start_date and b.effective_end_date
    914618 wrote:
    Hi all,
    Is it Possible to make a join from a single table
    Suppose HR_ALL_ORGANIZATION_UNITS table
    can we make a join in the following way
    HR_ALL_ORGANIZATION_UNITS.ORGANIZATION_ID =HR_ALL_ORGANIZATION_UNITS.BUSINESS_GROUP_ID
    Thanks in advance

  • How to write self join in sql?

    Hi,
    I have table named "table_upload", column "record_type" value "01,03,04....." and start_date,end_date and so on
    And i will have value for  start_date,end_date only for record_type=01,rest of type these two columns will be null.
    now i need to write query with self join, to include above concept. can any one please help me .
    and my query look like follows,

    I just want to re write
    Please provide DDL+DML + expected output!
    and short explanation what is it that we all ask you for:
    DDL = Data Definition Language. In our case that is, CREATE TABLE statements for your tables and other definitions that are needed to understand your tables structure and there for let us to test and reproduce the problem in our server. Without DDL no one
    can execute any query.
    How to get DDL: Right click on the table in Object Explorer and select script table as CREATE. Post these create table scripts here.
    DML = data manipulation language is a family of queries used for manipulating the data it self like: inserting, deleting and updating data. In our case we need some sample data in order to check the query and get result, so we need some indert query for
    sample data.
    If you post a "create table query" for the tables and "insert <table> query" with some sample, then we could help you without Assuming/Guessing. There is a reason that DDL is generally asked for and expected when discussing query problems - it helps
    to identify issues, clarify terminology and prevent incorrect assumptions.  Sample data also provides a common point of reference for the discussion. A script that can be used to illustrate or reproduce the issue you have, will encourage others to help.
    [Personal Site] [Blog] [Facebook]

  • Self join please help

    I would be very grateful if someone would show me show to use the self join, I understand what is does but just don't know how to use it. I have a question from a exercise but no answer so I can't check it the question is - using temporary labels to abbreviate table names, find all the staff that earn more than 'SONG'.
    here is the table
    STAFFID SNAME JOB MGR STARTDATE SAL COMM BRANCHID
    5963 SMITH ADMIN 5209 15-NOV-00 1600 20
    5994 BATES ASSISTANT 5896 20-FEB-01 1800 100 30
    5125 CHAN ASSISTANT 5896 22-FEB-02 1550 150 30
    5665 JONES MANAGER 5938 02-MAR-01 3100 20
    5465 WILSON ASSISTANT 5896 28-OCT-00 1250 140 30
    5896 HAYAT MANAGER 5938 01-MAY-01 3100 30
    5287 CLARK MANAGER 5938 09-JUL-02 3100 10
    5887 COSTA BUYER 5665 18-APR-04 3150 20
    5938 SHAW DIRECTOR 17-NOV-01 7000 10
    5484 TURNER ASSISTANT 5896 08-OCT-01 1550 0 30
    5678 KALIM ADMIN 5887 23-APR-04 1600 20
    5009 JAMES ADMIN 5896 03-DEC-01 1600 30
    5209 SONG BUYER 5665 03-JAN-02 3000 20
    5439 SIMPSON ADMIN 5287 23-FEB-02 1600 10
    Thanks in advanced :)
    Edited by: user11093259 on 01-Dec-2010 10:19

    Hi,
    Welcome to the forum!
    Always post your best attempt at solving the problem. You'll get more specific replies that will help you learn more, and it often clarifies what you're trying to do.
    Here's a typical self-join, using the scott.dept table (which you probably have avaialble).
    SELECT     l.dname          AS lower_dname
    ,     h.dname          AS higher_dname
    FROM     scott.dept     l
    JOIN     scott.dept     h  ON     l.dname     < h.dname
    ;Output:
    LOWER_DNAME    HIGHER_DNAME
    ACCOUNTING     OPERATIONS
    ACCOUNTING     RESEARCH
    ACCOUNTING     SALES
    OPERATIONS     RESEARCH
    OPERATIONS     SALES
    RESEARCH       SALESAs you can see, this pairs every higher_dname with every dname that is less than it.
    This is very similar to your problem. The main difference is, where the query above shows every possible higher_dname (and the lower_dnames related to it), you're interested in a single, specific higher value (and the rolws with lower values related to it). You can restrict the query to show only that one, specific higher values by adding a WHERE clause. Try it. If you get stuck, ask a more specific question, and, remember, post your code.

  • How to perform a self-join in WebI?

    Post Author: willgreenland
    CA Forum: WebIntelligence Reporting
    I want to perform a self-join on a table in WebI, in order to achieve the following result (of course, if there is another way of doing this I'd be glad to hear it):
    I have a table that lists the department in which an employee is located at given dates in the past:
    EMPLID    DEPT    DATE
    123                Sales    2007...
      I want to use this table to track migration between departments, in other words I want to produce the following output table, showing how in 2008, 5 employees moved from Sales to Marketing (etc):DEPT_A    DATE_A    DEPT_B    DATE_B    COUNT(EMPLID) Sales        2007          Mrkting      2008             5...
    In order to do this in SQL, I would do the following:
    SELECT a.DEPT, b.DEPT, count(distinct EMPLID)FROMEMPL_DEPT a, EMPL_DEPT b        // note the self-join hereWHERE( a.EMPLID = b.EMPLID AND a.DATE = '2007' AND b.DATE = '2008' )GROUP BY a.DEPT, b.DEPT;
    Is there a way of doing this in WebI, ideally without resorting to manual SQL editing (I want this to be a report that other users can make sense of without necessarily getting into the SQL)?

    Post Author: amr_foci
    CA Forum: WebIntelligence Reporting
    you cant do something like that in the WebI directly, you have to manager that at the unvinerse level first
    good luck

  • Adding a single table without a logical join to another table (OBIEE 10g)

    Sometimes I want to just display a single table without a logical join to another table in the repository. However, everytime I move it to the Business Model and Mapping layer and perform a Global Consistency Check, it tells me that it needs a logical join and I am forced to create another table to join to it. Thus creating a dimension-fact relationship. There are times I don't need this relationship and just want to display some data. Is there anyway to get around this?
    Thanks in advance!

    Yes,You have to create a join.You cannot take single table to BMM layer.You can create an alias of the table.Join this alias and base table through any common column and take both tables to BMM and desired table to presentation layer.
    Another way is to create a view in physcial layer.Write a select statement like
    Select primary_key from Table
    Where primary_key is primary key of base table.Join this view ith base table and repeat the steps defined for Alias.
    Regards,
    Sandeep

  • Lost Mode and Play Sound are "Pending."  However, iCloud indicates that it connected and backed up to iCloud at a date that is 1 week after it went missing.  How is this possible without locking (Lost Mode Pending an internet connection)

    Hi,
    My wife lost her iPhone two weeks ago while on vacation in London (cell service inoperative in foreign country).  Using Find My iPhone app on my device, I activated Lost Mode and Play Sound.  However, both are listed as "Pending," since it those actions require the phone to connect to the internet (wifi only due to no cellular data coverage.).
    We recently returned home and purchased a new iPhone.
    However, when looking to restore the apps/settings from her old phone using a previous iCloud backup, iCloud indicates that the old phone connected to iCloud and backed up the original phone at a date that is 1 week after it went missing.  How is this possible without locking (Lost Mode Pending an internet connection)?
    If the phone was activated and connected to the internet via a wifi signal, shouldn't it immedately lock, show up on the map, Play Sound, and send me an email that the phone has been found?
    I also read somewhere that if running iOS 7, the iCloud website interface enables you to track previous locations, for instance if the phone moves from wifi hotspot to hotspot.  Is that true?  If so, how do I do that?
    Thank you for your time, and have a great day!
    Sincerely,
    - Matt

    just giving this a wee bump as time is of the essence here and i need advice/ answers quick!
    apologies if i've broke any rules!
    alex

  • Is 1:n  possible without BPM

    I've 10 different items.Now i want to send these items to 10 different vendors.Is it possible without BPM?

    Of course
    Ref: /people/jin.shin/blog/2006/02/07/multi-mapping-without-bpm--yes-it146s-possible

  • Problem writing a XSLT to convert XML in desired format from a table having self join

    Hello,
    I have to write a style sheet to convert XML generated from XSQL into a different format. The query that I have is as follows.
    select LEVEL depth,
    'H' || hierarchy_id id,
    name,
    nvl2(parent_id, 'H' || parent_id, 0) parent_id,
    CURSOR(select LEVEL depth,
    'H' || hierarchy_id hid,
    name hname,
    nvl2(parent_id, 'H' || parent_id, 0) hparent_id,
    decode(system_id, NULL, '0', 'S' || system_id) formatted_system_id,
    system_id
    from hierarchy
    where parent_id = h.hierarchy_id
    and system_id is not null
    ) as systems
    from hierarchy h
    where system_id is null
    start with parent_id is null
    connect by prior hierarchy_id = parent_id
    The hierarchy table has a self join to itself. The selfjoin is on the hierarchyid and the parentid fields which is evident from the query.
    Here the hierarchy table contains the parent system and also the child systems underneath. The problem is that the no. of levels that it can go deep is not fixed. The output of this in sqlplus is as follows.
    Depth Hierarchyid, name parentid
    1 h1 xxx <null>
    2 h2 bbb h1
    3 h3 ccc h2
    <Cursor for systems>
    hid hname hparentid formatted_system_id systemid
    h4 ccc h2 s1 1
    h5 ccc h2 s2 2
    <Back to original data>
    Depth Hierarchyid, name parentid
    2 h6 ddd h1
    2 h7 eee h1
    The desired output required from the stylesheet is as follows
    <h id=h1 name=xxx>
    <h id=h2 name=bbb parentid=h1>
    <h id=h3 name=ccc parentid=h2>
    <h id=h4 name=fff parentid=h3 systemid=s1>
    <h id=h5 name=ggg parentid=h3 systemid=s2>
    </h>
    </h>
    <h id=h6 name=ddd parentid=h1/>
    <h id=h7 name=eee parentid=h1/>
    </h>
    Could some one guide me as to how to get this. I did write a stylesheet which gives me the following output.
    <h id=h1 name=xxx>
    <h id=h2 name=bbb parentid=h1/>
    <h id=h3 name=ccc parentid=h2/>
    <h id=h4 name=fff parentid=h3 systemid=s1>
    <h id=h5 name=ggg parentid=h3 systemid=s2>
    </h>
    <h id=h6 name=ddd parentid=h1/>
    <h id=h7 name=eee parentid=h1/>
    </h>
    As you can see I am missing the closing of the tag on the 7th line in the desired format. I have written the following stylesheet.
    <!-- Hierarchy.xsl: Transform ROWSET/ROW format to the required Hierarchy format. -->
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="node()|@*">
    <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
    </xsl:template>
    <!-- Template for matching the rowset..... -->
    <xsl:template match="HIERARCHY">
    <HIERARCHY><xsl:apply-templates/></HIERARCHY>
    </xsl:template>
    <!-- Template for matching the row .... -->
    <xsl:template match="HELEMENT">
    <xsl:choose>
    <xsl:when test="PARENT_ID=0">
    <helement id="{ID}" name="{NAME}" parentid="{PARENT_ID}"/>
    </xsl:when>
    <xsl:when test="PARENT_ID!='0'">
    <helement2 id="{ID}" name="{NAME}" parentid="{PARENT_ID}">
    <xsl:for-each select="SYSTEMS/SYSTEMS_ROW">
    <helement3 id="{HID}" name="{HNAME}" parentid="{HPARENT_ID}" systemid="{FORMATTED_SYSTEM_ID}">
    </helement3>
    </xsl:for-each>
    </helement2>
    </xsl:when>
    <xsl:otherwise>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>
    </xsl:stylesheet>
    Is there any way of achieving this. Any help would be appreciated. I am using XSQL to generate first the basic XML output and then applying stylesheet to achieve the desired output.
    Sincerely,
    D

    Hello,
    I have to write a style sheet to convert XML generated from XSQL into a different format. The query that I have is as follows.
    select LEVEL depth,
    'H' || hierarchy_id id,
    name,
    nvl2(parent_id, 'H' || parent_id, 0) parent_id,
    CURSOR(select LEVEL depth,
    'H' || hierarchy_id hid,
    name hname,
    nvl2(parent_id, 'H' || parent_id, 0) hparent_id,
    decode(system_id, NULL, '0', 'S' || system_id) formatted_system_id,
    system_id
    from hierarchy
    where parent_id = h.hierarchy_id
    and system_id is not null
    ) as systems
    from hierarchy h
    where system_id is null
    start with parent_id is null
    connect by prior hierarchy_id = parent_id
    The hierarchy table has a self join to itself. The selfjoin is on the hierarchyid and the parentid fields which is evident from the query.
    Here the hierarchy table contains the parent system and also the child systems underneath. The problem is that the no. of levels that it can go deep is not fixed. The output of this in sqlplus is as follows.
    Depth Hierarchyid, name parentid
    1 h1 xxx <null>
    2 h2 bbb h1
    3 h3 ccc h2
    <Cursor for systems>
    hid hname hparentid formatted_system_id systemid
    h4 ccc h2 s1 1
    h5 ccc h2 s2 2
    <Back to original data>
    Depth Hierarchyid, name parentid
    2 h6 ddd h1
    2 h7 eee h1
    The desired output required from the stylesheet is as follows
    <h id=h1 name=xxx>
    <h id=h2 name=bbb parentid=h1>
    <h id=h3 name=ccc parentid=h2>
    <h id=h4 name=fff parentid=h3 systemid=s1>
    <h id=h5 name=ggg parentid=h3 systemid=s2>
    </h>
    </h>
    <h id=h6 name=ddd parentid=h1/>
    <h id=h7 name=eee parentid=h1/>
    </h>
    Could some one guide me as to how to get this. I did write a stylesheet which gives me the following output.
    <h id=h1 name=xxx>
    <h id=h2 name=bbb parentid=h1/>
    <h id=h3 name=ccc parentid=h2/>
    <h id=h4 name=fff parentid=h3 systemid=s1>
    <h id=h5 name=ggg parentid=h3 systemid=s2>
    </h>
    <h id=h6 name=ddd parentid=h1/>
    <h id=h7 name=eee parentid=h1/>
    </h>
    As you can see I am missing the closing of the tag on the 7th line in the desired format. I have written the following stylesheet.
    <!-- Hierarchy.xsl: Transform ROWSET/ROW format to the required Hierarchy format. -->
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="node()|@*">
    <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
    </xsl:template>
    <!-- Template for matching the rowset..... -->
    <xsl:template match="HIERARCHY">
    <HIERARCHY><xsl:apply-templates/></HIERARCHY>
    </xsl:template>
    <!-- Template for matching the row .... -->
    <xsl:template match="HELEMENT">
    <xsl:choose>
    <xsl:when test="PARENT_ID=0">
    <helement id="{ID}" name="{NAME}" parentid="{PARENT_ID}"/>
    </xsl:when>
    <xsl:when test="PARENT_ID!='0'">
    <helement2 id="{ID}" name="{NAME}" parentid="{PARENT_ID}">
    <xsl:for-each select="SYSTEMS/SYSTEMS_ROW">
    <helement3 id="{HID}" name="{HNAME}" parentid="{HPARENT_ID}" systemid="{FORMATTED_SYSTEM_ID}">
    </helement3>
    </xsl:for-each>
    </helement2>
    </xsl:when>
    <xsl:otherwise>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>
    </xsl:stylesheet>
    Is there any way of achieving this. Any help would be appreciated. I am using XSQL to generate first the basic XML output and then applying stylesheet to achieve the desired output.
    Sincerely,
    D

Maybe you are looking for

  • Open in a new window on click of hyperlink

    Hi, I have created a BSP application which display partner details. here Partner ID is a hyperlink. On click of the hyperlink it is opening in the Same page. I need to open this in a new page. below is the code         <htmlb:tableViewColumn columnNa

  • PDF version of presenter files - where does the attachments icon go?

    When I save my Presenter files to the server, I can link in attachments related to the presentation. http://breeze.unisa.edu.au/test11-09/ When I save the same files as a pdf - the GUI no longer has a paperclip icon to access the attachments. Is this

  • Import package with .* in jsp

    If i want to use HashMap in jsp page i need to have HashMap of util package in import statment in page directive. What is difference in Using a) <%@ page import="java.util.HashMap"%> b) <%@ page import="java.util.*"%> Is there any performance issue u

  • Outer join style report - OBIEE 10g

    Hi All, I have a requirement to generate a report for product & sales. I have two dimensions and various fact data elements. Some products may not be sold on a month but still i want to display them in the report with 0 value. I have tried this by cr

  • How 2 create an 'unread documents' TREX search iView

    Hi, I'm trying to create a TREX seach iview (EP6SPS9) which shows all unread documents as a result. The property acc:cm_lastreaddate seems suitable to use in the 'query' section of the searchiview. This one works fine (result = show documents which w