SQL XML Query Help

I have four tables and I want to create one XML file. I provided the temp tables with
data and expected output.
create table #ZDL(ZLN bigint, ZTLA int, ZMR decimal, ZCLS varchar(20), ZPITIP money)
insert into #ZDL values(1234, 200000, 8.5, 'CART', 1500.00)
create table #ZBL(ZLN bigint, ZBN varchar(50), ZFN varchar(20), ZMN varchar(8), ZLL varchar(20))
insert into #ZBL values(1234, 'TEST Test', 'TEST', null, 'Test')
create table #ZCC(ZLN bigint, ZSN int, ZCE int)
insert into #ZCC values(1234, 1, 4)
create table #ZP(ZLN bigint, ZPT varchar(50), ZPP int, ZNU int)
insert into #ZP values(1234, 'Attached', 6500, 3)
Expected XML Result should be:
<TEST_DATA xmlns="http://www.TestData.com/Schema/Test"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.TestData.com/Schema/Test_Schema.xsd">
<KEY _Name="ZID" _Value="789" _ID="ZID"/>
<ZL>
<ZLN>1234</ZLN>
<ZTLA>200000</ZTLA>
<ZMR>8.5</ZMR>
<ZCLS>CART</ZCLS>
<ZPITIP>1500.00</ZPITIP>
</ZL>
<ZBS>
<ZB>
<ZBN>TEST Test</ZBN>
<ZFN>TEST</ZFN>
<ZMN></ZMN>
<ZLL>Test</ZLL>
</ZB>
</ZBS>
<ZCC>
<ZC>
<ZSN>1</ZSN>
<ZCE>4</ZCE>
</ZC>
</ZCC>
<ZP>
<ZPT>Attached</ZPT>
<ZPP>6500</ZPP>
<ZNU>3</ZNU>
</ZP>
</TEST_DATA>
Thanks

little change in your query as OP expected
SELECT
(SELECT ZLN ,
ZTLA ,
ZMR ,
ZCLS,
ZPITIP --AS [*]
FROM #ZDL
WHERE ZLN = z1.ZLN
FOR XML PATH('ZL'),TYPE) AS [*],
(SELECT
ZBN ,--AS [*],
ZFN ,
ISNULL(ZMN,'') AS ZMN ,
ZLL
FROM #ZBL
WHERE ZLN = z1.ZLN
FOR XML PATH('ZB'),TYPE) AS [ZBS],
(SELECT
ZSN,ZCE
FROM #ZCC
WHERE ZLN = z1.ZLN
FOR XML PATH('ZC'),TYPE) AS [ZCC],
(SELECT
ZPT,
ZPP,
ZNU
FROM #ZP
WHERE ZLN = z1.ZLN
FOR XML PATH('ZP'),TYPE) AS [*]
FROM (SELECT DISTINCT ZLN FROM #ZDL) z1
FOR XML PATH('TEST_DATA')
Nope
it will give different output
see the difference
mine
<TEST_DATA>
<ZL>
<ZLN>1234</ZLN>
<ZTLA>200000</ZTLA>
<ZMR>9</ZMR>
<ZCLS>CART</ZCLS>
1500.0000
</ZL>
<ZBS>
<ZB>
TEST Test
<ZFN>TEST</ZFN>
<ZMN />
<ZLL>Test</ZLL>
</ZB>
</ZBS>
<ZCC>
<ZC>
<ZSN>1</ZSN>
<ZCE>4</ZCE>
</ZC>
</ZCC>
<ZP>
<ZPT>Attached</ZPT>
<ZPP>6500</ZPP>
<ZNU>3</ZNU>
</ZP>
</TEST_DATA>
and see your output
<TEST_DATA>
<ZL>
<ZLN>1234</ZLN>
<ZTLA>200000</ZTLA>
<ZMR>9</ZMR>
<ZCLS>CART</ZCLS>
<ZPITIP>1500.0000</ZPITIP>
</ZL>
<ZBS>
<ZB>
<ZBN>TEST Test</ZBN>
<ZFN>TEST</ZFN>
<ZMN />
<ZLL>Test</ZLL>
</ZB>
</ZBS>
<ZCC>
<ZC>
<ZSN>1</ZSN>
<ZCE>4</ZCE>
</ZC>
</ZCC>
<ZP>
<ZPT>Attached</ZPT>
<ZPP>6500</ZPP>
<ZNU>3</ZNU>
</ZP>
</TEST_DATA>
Its different from what Op wanted
my suggestion gives exactly in the format wanted
notice extra nodes ZPITIP and ZLN
coming in your case
Your original suggestion also has this issues
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

Similar Messages

  • How to tune the performance of Oracle SQL/XML query?

    Hi all,
    I am running Oracle 9i and like to run the following Oracle SQL/XML query. It takes about 3+ hour and still not finish. If I get rid all the XML stuffs it only take minutes to run. Does anybody know how to what's the reason of this slow and how to tune it?
    SELECT XMLElement("CUSTOMER",
    XMLForest(C_CUSTKEY "C_CUSTKEY", C_NAME "C_NAME", C_ADDRESS "C_ADDRESS", C_PHONE "C_PHONE", C_MKTSEGMENT "C_MKTSEGMENT", C_COMMENT "C_COMMENT"),
    (SELECT XMLAgg(XMLElement("ORDERS",
    XMLForest(O_ORDERKEY "O_ORDERKEY", O_CUSTKEY "O_CUSTKEY", O_ORDERSTATUS "O_ORDERSTATUS", O_ORDERPRIORITY "O_ORDERPRIORITY", O_CLERK "O_CLERK", O_COMMENT "O_COMMENT"),
    (SELECT XMLAgg(XMLElement("LINEITEM",
    XMLForest(L_ORDERKEY "L_ORDERKEY", L_RETURNFLAG "L_RETURNFLAG", L_LINESTATUS "L_LINESTATUS", L_SHIPINSTRUCT "L_SHIPINSTRUCT", L_SHIPMODE "L_SHIPMODE", L_COMMENT "L_COMMENT")
    FROM LINEITEM
    WHERE LINEITEM.L_ORDERKEY = ORDERS.O_ORDERKEY)
    FROM ORDERS
    WHERE ORDERS.O_CUSTKEY = CUSTOMER.C_CUSTKEY)
    FROM CUSTOMER ;
    Thanks very much in advance for your time,
    Jinghao Liu

    ajallen wrote:
    Why not something more like
    SELECT *
    FROM fact1 l,
    FULL OUTER JOIN fact1 d
    ON l.company = d.company
    AND l.transactiontypeid = 1
    AND d.transactiontypeid = 2;
    Because this is not an equivalent of the original query.
    drop table t1 cascade constraints purge;
    drop table t2 cascade constraints purge;
    create table t1 as select rownum t1_id from dual connect by level <= 5;
    create table t2 as select rownum+2 t2_id from dual connect by level <= 5;
    select * from (select * from t1 where t1_id > 2) t1 full outer join t2 on (t1_id = t2_id);
    select * from t1 full outer join t2 on (t1_id = t2_id and t1_id > 2);
         T1_ID      T2_ID
             3          3
             4          4
             5          5
                        6
                        7
         T1_ID      T2_ID
             1
             2
             3          3
             4          4
             5          5
                        6
                        7

  • How to perf tune Oracle SQL/XML query?

    Hi all,
    I am using Oracle 9i and like to run the following Oracle SQL/XML query. It takes about 3+ hour and still not finish. If I get rid all the XML stuffs it only take minutes to run. Does anybody know how to what's the reason of this slow and how to tune it?
    SELECT XMLElement("CUSTOMER",
    XMLForest(C_CUSTKEY "C_CUSTKEY", C_NAME "C_NAME", C_ADDRESS "C_ADDRESS", C_PHONE "C_PHONE", C_MKTSEGMENT "C_MKTSEGMENT", C_COMMENT "C_COMMENT"),
    (SELECT XMLAgg(XMLElement("ORDERS",
    XMLForest(O_ORDERKEY "O_ORDERKEY", O_CUSTKEY "O_CUSTKEY", O_ORDERSTATUS "O_ORDERSTATUS", O_ORDERPRIORITY "O_ORDERPRIORITY", O_CLERK "O_CLERK", O_COMMENT "O_COMMENT"),
    (SELECT XMLAgg(XMLElement("LINEITEM",
    XMLForest(L_ORDERKEY "L_ORDERKEY", L_RETURNFLAG "L_RETURNFLAG", L_LINESTATUS "L_LINESTATUS", L_SHIPINSTRUCT "L_SHIPINSTRUCT", L_SHIPMODE "L_SHIPMODE", L_COMMENT "L_COMMENT")
    FROM LINEITEM
    WHERE LINEITEM.L_ORDERKEY = ORDERS.O_ORDERKEY)
    FROM ORDERS
    WHERE ORDERS.O_CUSTKEY = CUSTOMER.C_CUSTKEY)
    FROM CUSTOMER ;
    Thanks very much in advance for your time,
    Jinghao Liu

    Please post this message at:
    Forums Home » Oracle Technology Network (OTN) » Products » Database » XML DB

  • XML Query Help row with no data

    declare @address table
    AddressID int,
    AddressType varchar(12),
    Address1 varchar(20),
    Address2 varchar(20),
    City varchar(25),
    AgentID int
    insert into @address 
    select 1, 'Home', 'abc', 'xyz road', 'RJ', 1 union all
    select 2, 'Office', 'temp', 'ppp road', 'RJ', 1 union all
    select 3, 'Home', 'xxx', 'aaa road', 'NY', 2 union all
    select 4, 'Office', 'ccc', 'oli Com', 'CL', 2 union all
    select 5, 'Temp', 'eee', 'olkiu road', 'CL', 2 union all
    select 6, 'Home', 'ttt', 'loik road', 'NY', 3
    SELECT a.* from @address a 
    where a.AddressID = 1
    FOR XML path('Addresses')
    SELECT a.* from @address a 
    where a.AddressID = 9
    FOR XML path('Addresses')
    Issue:
    As you can see for second query where AddressID = 9 is not exists so xml is not generated but
    my expected result is for second query is
    <Addresses>
    <AddressID />
    <AddressType />
    <Address1 />
    <Address2 />
    <City />
    <AgentID />
    </Addresses>
    Thanks in advance for all your help. 

    First of all: Your expectation is wrong. Sorry to say that. But your SQL statement for A.AddressID = 9 does not return a row. So no row is converted. I hope you C it: void.
    From the XML viewpoint:
    <Addresses>
    <AddressID />
    <AddressType />
    <Address1 />
    <Address2 />
    <City />
    <AgentID />
    </Addresses>
    is equivalent to
    <Addresses />
    which is equivalent to
    void
    You C. Sorry got infeCted some how ;)
    The only meaningful result in XML would be:
    <Addresses ID="1">
    <AddressType>Home</AddressType>
    <Address1>abc</Address1>
    <Address2>xyz road</Address2>
    <City>RJ</City>
    <AgentID>1</AgentID>
    </Addresses>
    <Addresses ID="9"/>
    Cause now Addresses (Really? A plural form for a single entity?) transports the meaning, well there is no data (no row) for it. We tried to find it, but we failed. In opposite to
    <Addresses>
    <AddressID>9</AddressID>
    <AddressType />
    <Address1 />
    <Address2 />
    <City />
    <AgentID />
    </Addresses>
    <Addresses ID="9">
    <AddressType />
    <Address1 />
    <Address2 />
    <City />
    <AgentID />
    </Addresses>
    Which says: well, we have a row with the ID 9, but the rest of the columns is empty.
    The problem is mere semantics. But it's an important difference.
    Now for your problem: Why do you expect this? Where do can you work with such a kind of informationless result?
    btw, as you're using already a table variable (+1), you should also use
    table value constructors like
    INSERT INTO @address
    VALUES ( 1, 'Home', 'abc', 'xyz road', 'RJ', 1 ),
    ( 2, 'Office', 'temp', 'ppp road', 'RJ', 1 ),
    ( 3, 'Home', 'xxx', 'aaa road', 'NY', 2 ),
    ( 4, 'Office', 'ccc', 'oli Com', 'CL', 2 ),
    ( 5, 'Temp', 'eee', 'olkiu road', 'CL', 2 ),
    ( 6, 'Home', 'ttt', 'loik road', 'NY', 3 );
    I would use a tally table, when you really need this:
    DECLARE @address TABLE
    AddressID INT ,
    AddressType VARCHAR(12) ,
    Address1 VARCHAR(20) ,
    Address2 VARCHAR(20) ,
    City VARCHAR(25) ,
    AgentID INT
    INSERT INTO @address
    VALUES ( 1, 'Home', 'abc', 'xyz road', 'RJ', 1 ),
    ( 2, 'Office', 'temp', 'ppp road', 'RJ', 1 ),
    ( 3, 'Home', 'xxx', 'aaa road', 'NY', 2 ),
    ( 4, 'Office', 'ccc', 'oli Com', 'CL', 2 ),
    ( 5, 'Temp', 'eee', 'olkiu road', 'CL', 2 ),
    ( 6, 'Home', 'ttt', 'loik road', 'NY', 3 );
    WITH n1
    AS ( SELECT *
    FROM ( VALUES ( 1), ( 1), ( 1), ( 1) ) Q ( n )
    n2
    AS ( SELECT a.n
    FROM n1 a ,
    n1 b ,
    n1 c ,
    n1 d
    NumberTally
    AS ( SELECT ROW_NUMBER() OVER ( ORDER BY n ) AS n
    FROM n2
    SELECT NT.n AS [@ID] ,
    a.AddressType ,
    a.Address1 ,
    a.Address2 ,
    a.City ,
    a.AgentID
    FROM NumberTally NT
    LEFT JOIN @address a ON a.AddressID = NT.n
    WHERE NT.n IN ( 1, 9 )
    FOR XML PATH('Address');
    or the void version:
    DECLARE @address TABLE
    AddressID INT ,
    AddressType VARCHAR(12) ,
    Address1 VARCHAR(20) ,
    Address2 VARCHAR(20) ,
    City VARCHAR(25) ,
    AgentID INT
    INSERT INTO @address
    VALUES ( 1, 'Home', 'abc', 'xyz road', 'RJ', 1 ),
    ( 2, 'Office', 'temp', 'ppp road', 'RJ', 1 ),
    ( 3, 'Home', 'xxx', 'aaa road', 'NY', 2 ),
    ( 4, 'Office', 'ccc', 'oli Com', 'CL', 2 ),
    ( 5, 'Temp', 'eee', 'olkiu road', 'CL', 2 ),
    ( 6, 'Home', 'ttt', 'loik road', 'NY', 3 );
    WITH n1
    AS ( SELECT *
    FROM ( VALUES ( 1), ( 1), ( 1), ( 1) ) Q ( n )
    n2
    AS ( SELECT a.n
    FROM n1 a ,
    n1 b ,
    n1 c ,
    n1 d
    NumberTally
    AS ( SELECT ROW_NUMBER() OVER ( ORDER BY n ) AS n
    FROM n2
    SELECT a.AddressID AS [@ID] ,
    a.AddressType ,
    a.Address1 ,
    a.Address2 ,
    a.City ,
    a.AgentID
    FROM NumberTally NT
    LEFT JOIN @address a ON a.AddressID = NT.n
    WHERE NT.n IN ( 1, 9 )
    FOR XML PATH('Address');

  • XML QUERY HELP NEEDED

    Hi,
    Need help in writing a query.
    SQL> SELECT xmlelement("P",xmlforest(P.process_id AS Ppid),
      2   xmlagg(xmlelement("PI",XMLFOREST( PI.question_id AS PIqid,
      3   PI.process_id AS PIpid,
      4   PI.innertext AS PItext),
      5   xmlagg(Xmlelement("PO",xmlforest( PO.option_id AS POoid,
      6   PO.question_id AS POqid,
      7   PO.process_id AS popid
      8   ))
      9  ORDER BY PO.option_id))
    10     ORDER BY PI.question_id ) )
    11     FROM liveProcess_ec P
    12  INNER JOIN vw_liveProcessItem_Sim_v6 PI
    13       ON P.process_id = PI.process_id
    14  LEFT OUTER JOIN vw_liveProcessOption_Sim_v6 PO
    15       ON PI.question_id = PO.question_id
    16  AND PI.process_id      = PO.process_id
    17    WHERE p.process_id   =450
    18  GROUP BY p.process_id,PI.question_id,PI.process_id,PI.innertext
    19    ORDER BY p.process_id;
    SELECT xmlelement("P",xmlforest(P.process_id AS Ppid),
    ERROR at line 1:
    ORA-00937: not a single-group group functionThanks in advance

    Hi,
    Here below are the create table scripts along with sample data and expected output.
    CREATE TABLE VW_LIVEPROCESSOPTION_SIM_v6
    ( "OPTION_ID" NUMBER,
    "QUESTION_ID" NUMBER(10,0),
    "PROCESS_ID" NUMBER(10,0),
    "OPT_INNERTEXT" VARCHAR2(200 CHAR),
    "OPT_LINKFROM" VARCHAR2(20 CHAR),
    "OPT_LINKTO" VARCHAR2(20 CHAR),
    "LIBQUESTION_IDFK" NUMBER,
    "LIBOPTION_IDFK" NUMBER
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,2,450,'Yes',null,'5',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,3,450,'Yes',null,'5',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,5,450,'Yes',null,'6',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,6,450,'Yes',null,'7',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,8,450,'Block All',null,'9',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,9,450,'Yes',null,'10',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,11,450,'Yes',null,'12',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,12,450,'Yes',null,'13',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (1,14,450,'Yes',null,'16',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,2,450,'No',null,'3',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,3,450,'No',null,'4',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,5,450,'No',null,'8',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,6,450,'No',null,'8',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,8,450,'Standard',null,'11',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,9,450,'No',null,'11',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,11,450,'No',null,'14',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,12,450,'No',null,'14',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (2,14,450,'No',null,'15',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (3,8,450,'Disabled',null,'12',null,null);
    Insert into VW_LIVEPROCESSOPTION_SIM_v6(OPTION_ID,QUESTION_ID,PROCESS_ID,OPT_INNERTEXT,OPT_LINKFROM,OPT_LINKTO,LIBQUESTION_IDFK,LIBOPTION_IDFK) values (4,8,450,'User Defined',null,'12',null,null);
    REATE TABLE "VW_LIVEPROCESSITEM_SIM_v6"
    ( "QUESTION_ID" NUMBER(10,0),
    "PROCESS_ID" NUMBER(10,0),
    "INNERTEXT" VARCHAR2(200 CHAR),
    "ITEMTYPE" VARCHAR2(50 CHAR),
    "LINKFROM" VARCHAR2(500 CHAR),
    "LINKTO" VARCHAR2(500 CHAR),
    "ASSOCIATED" VARCHAR2(200 CHAR),
    "CONTENT_ID" NUMBER,
    "EXITPOINT1_ID" NUMBER(10,0),
    "EXITPOINT2_ID" NUMBER(10,0),
    "EXITPOINT3_ID" NUMBER(10,0),
    "RESOLVEIDENTIFIER" VARCHAR2(40 CHAR),
    "LIBQUESTION_IDFK" NUMBER(10,0),
    "FOLLOWONCALL" NUMBER(1,0),
    "USERINPUT" VARCHAR2(200 CHAR),
    "ISLOCKED" NUMBER(1,0),
    "PREVIOUSANSWER" NUMBER(1,0),
    "VISIBLETOAGENT" NUMBER(1,0),
    "RETRYATTEMPT" NUMBER(10,0),
    "TAGS" VARCHAR2(50 BYTE)
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (1,450,'CBB1015 - Router Firewall Settinngs Process','Title',null,'2',null,null,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (2,450,'Is the customers PC Firewall turned off?','Question','1','2.2,2.1',null,null,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (3,450,'Advise the customer to turn off the PC Firewall in order to continue. Has this been done?','Question','2.2','3.2,3.1',null,278,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (4,450,'Advise the customer the PC Firewall must be switched off before this process????','ExitPoint','3.2',null,null,null,14,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (5,450,'Is the customer able to access the internet now?','Question','3.1,2.1','5.2,5.1',null,null,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (6,450,'Is the customer having a problem with a specific website?','Question','5.1','6.2,6.1',null,null,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (7,450,'1536: CBB1008 - Browser Setup and Daignostics','SubProcess','6.1',null,'1536-1-0',null,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (8,450,'What is the security level on the CPE Management page?','Question','6.2,5.2','8.4,8.3,8.2,8.1',null,279,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (9,450,'Change the security level to Standard. Does this resolve the customers issue?','Question','8.1','9.2,9.1',null,280,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (10,450,'Issue Resolved','ExitPoint','9.1',null,null,null,1,6,122,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (11,450,'Change the security level to Disabled. Is the customer able to browse the internet?','Question','9.2,8.2','11.2,11.1',null,281,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (12,450,'Change the security level to Standard. Is the customer able to browse the internet now?','Question','11.1,8.3,8.4','12.2,12.1',null,283,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (13,450,'Issue Resolved','ExitPoint','12.1',null,null,null,1,6,123,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (14,450,'Ask the customer to perform a master reset. Does this resolve their issue?','Question','12.2,11.2','14.2,14.1',null,282,null,null,null,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (15,450,'Faulty CPE','ExitPoint','14.2',null,null,null,1,6,124,null,null,null,null,null,null,null,null,null);
    Insert into VW_LIVEPROCESSITEM_SIM_v6 (QUESTION_ID,PROCESS_ID,INNERTEXT,ITEMTYPE,LINKFROM,LINKTO,ASSOCIATED,CONTENT_ID,EXITPOINT1_ID,EXITPOINT2_ID,EXITPOINT3_ID,RESOLVEIDENTIFIER,LIBQUESTION_IDFK,FOLLOWONCALL,USERINPUT,ISLOCKED,PREVIOUSANSWER,VISIBLETOAGENT,RETRYATTEMPT,TAGS) values (16,450,'Issue Resolved','ExitPoint','14.1',null,null,null,1,6,123,null,null,null,null,null,null,null,null,null);
    CREATE TABLE "LIVEPROCESS_EC_V"
    ( "PROCESS_ID" NUMBER(10,0),
    "USER_ID" NUMBER(10,0),
    "CREATED" TIMESTAMP (6)
    Insert into LIVEPROCESS_EC (PROCESS_ID,USER_ID,CREATED) values (450,7460,to_timestamp('21-APR-08 09.34.41.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'));Expected Output
    <P>
      <Ppid>450</Ppid>
      <Pn>CBB1015 - Router Firewall Settinngs Process</Pn>
      <Pg>9</Pg>
      <Pl>0</Pl>
      <Pb>5</Pb>
      <qcount>100</qcount>
      <ocount>200</ocount>
      <PI>
        <PIqid>1</PIqid>
        <PIpid>450</PIpid>
        <PIpx>366</PIpx>
        <PIpy>-516</PIpy>
        <PItext>CBB1015 - Router Firewall Settinngs Process</PItext>
        <PItype>Title</PItype>
        <PIto>2</PIto>
        <PO />
      </PI>
      <PI>
        <PIqid>2</PIqid>
        <PIpid>450</PIpid>
        <PIpx>366</PIpx>
        <PIpy>-437</PIpy>
        <PItext>Is the customers PC Firewall turned off?</PItext>
        <PItype>Question</PItype>
        <PIfrom>1</PIfrom>
        <PIto>2.2,2.1</PIto>
        <PO>
          <POoid>1</POoid>
          <POqid>2</POqid>
          <popid>450</popid>
          <POpx>-50</POpx>
          <POpy>70</POpy>
          <POtext>Yes</POtext>
          <POto>5</POto>
        </PO>
        <PO>
          <POoid>2</POoid>
          <POqid>2</POqid>
          <popid>450</popid>
          <POpx>50</POpx>
          <POpy>70</POpy>
          <POtext>No</POtext>
          <POto>3</POto>
        </PO>
      </PI>
      <PI>
        <PIqid>3</PIqid>
        <PIpid>450</PIpid>
        <PIpx>468</PIpx>
        <PIpy>-344</PIpy>
        <PItext>Advise the customer to turn off the PC Firewall in order to continue. Has this been done?</PItext>
        <PItype>Question</PItype>
        <PIfrom>2.2</PIfrom>
        <PIto>3.2,3.1</PIto>
        <PIc>278</PIc>
        <PO>
          <POoid>1</POoid>
          <POqid>3</POqid>
          <popid>450</popid>
          <POpx>-50</POpx>
          <POpy>70</POpy>
          <POtext>Yes</POtext>
          <POto>5</POto>
        </PO>
        <PO>
          <POoid>2</POoid>
          <POqid>3</POqid>
          <popid>450</popid>
          <POpx>50</POpx>
          <POpy>70</POpy>
          <POtext>No</POtext>
          <POto>4</POto>
        </PO>
      </PI>
      <PI>
        <PIqid>4</PIqid>
        <PIpid>450</PIpid>
        <PIpx>571</PIpx>
        <PIpy>-250</PIpy>
        <PItext>Advise the customer the PC Firewall must be switched off before this process????</PItext>
        <PItype>ExitPoint</PItype>
        <PIfrom>3.2</PIfrom>
        <PIe1>14</PIe1>
        <PO />
      </PI>
      <PI>
        <PIqid>5</PIqid>
        <PIpid>450</PIpid>
        <PIpx>374</PIpx>
        <PIpy>-240</PIpy>
        <PItext>Is the customer able to access the internet now?</PItext>
        <PItype>Question</PItype>
        <PIfrom>3.1,2.1</PIfrom>
        <PIto>5.2,5.1</PIto>
        <PO>
          <POoid>1</POoid>
          <POqid>5</POqid>
          <popid>450</popid>
          <POpx>-50</POpx>
          <POpy>70</POpy>
          <POtext>Yes</POtext>
          <POto>6</POto>
        </PO>
        <PO>
          <POoid>2</POoid>
          <POqid>5</POqid>
          <popid>450</popid>
          <POpx>50</POpx>
          <POpy>70</POpy>
          <POtext>No</POtext>
          <POto>8</POto>
        </PO>
      </PI>
      <PI>
        <PIqid>6</PIqid>
        <PIpid>450</PIpid>
        <PIpx>322</PIpx>
        <PIpy>-141</PIpy>
        <PItext>Is the customer having a problem with a specific website?</PItext>
        <PItype>Question</PItype>
        <PIfrom>5.1</PIfrom>
        <PIto>6.2,6.1</PIto>
        <PO>
          <POoid>1</POoid>
          <POqid>6</POqid>
          <popid>450</popid>
          <POpx>-50</POpx>
          <POpy>70</POpy>
          <POtext>Yes</POtext>
          <POto>7</POto>
        </PO>
        <PO>
          <POoid>2</POoid>
          <POqid>6</POqid>
          <popid>450</popid>
          <POpx>50</POpx>
          <POpy>70</POpy>
          <POtext>No</POtext>
          <POto>8</POto>
        </PO>
      </PI>
      <PI>
        <PIqid>7</PIqid>
        <PIpid>450</PIpid>
        <PIpx>128</PIpx>
        <PIpy>-36</PIpy>
        <PItext>1536: CBB1008 - Browser Setup and Daignostics</PItext>
        <PItype>SubProcess</PItype>
        <PIfrom>6.1</PIfrom>
        <PIas>1536-1-0</PIas>
        <PO />
      </PI>
      <PI>
        <PIqid>8</PIqid>
        <PIpid>450</PIpid>
        <PIpx>461</PIpx>
        <PIpy>-43</PIpy>
        <PItext>What is the security level on the CPE Management page?</PItext>
        <PItype>Question</PItype>
        <PIfrom>6.2,5.2</PIfrom>
        <PIto>8.4,8.3,8.2,8.1</PIto>
        <PIc>279</PIc>
        <PO>
          <POoid>1</POoid>
          <POqid>8</POqid>
          <popid>450</popid>
          <POpx>-112</POpx>
          <POpy>89</POpy>
          <POtext>Block All</POtext>
          <POto>9</POto>
        </PO>
        <PO>
          <POoid>2</POoid>
          <POqid>8</POqid>
          <popid>450</popid>
          <POpx>50</POpx>
          <POpy>70</POpy>
          <POtext>Standard</POtext>
          <POto>11</POto>
        </PO>
        <PO>
          <POoid>3</POoid>
          <POqid>8</POqid>
          <popid>450</popid>
          <POpx>83</POpx>
          <POpy>116</POpy>
          <POtext>Disabled</POtext>
          <POto>12</POto>
        </PO>
        <PO>
          <POoid>4</POoid>
          <POqid>8</POqid>
          <popid>450</popid>
          <POpx>-14</POpx>
          <POpy>94</POpy>
          <POtext>User Defined</POtext>
          <POto>12</POto>
        </PO>
      </PI>
      <PI>
        <PIqid>9</PIqid>
        <PIpid>450</PIpid>
        <PIpx>237</PIpx>
        <PIpy>76</PIpy>
        <PItext>Change the security level to Standard. Does this resolve the customers issue?</PItext>
        <PItype>Question</PItype>
        <PIfrom>8.1</PIfrom>
        <PIto>9.2,9.1</PIto>
        <PIc>280</PIc>
        <PO>
          <POoid>1</POoid>
          <POqid>9</POqid>
          <popid>450</popid>
          <POpx>-50</POpx>
          <POpy>70</POpy>
          <POtext>Yes</POtext>
          <POto>10</POto>
        </PO>
        <PO>
          <POoid>2</POoid>
          <POqid>9</POqid>
          <popid>450</popid>
          <POpx>69</POpx>
          <POpy>73</POpy>
          <POtext>No</POtext>
          <POto>11</POto>
        </PO>
      </PI>
      <PI>
        <PIqid>10</PIqid>
        <PIpid>450</PIpid>
        <PIpx>158</PIpx>
        <PIpy>185</PIpy>
        <PItext>Issue Resolved</PItext>
        <PItype>ExitPoint</PItype>
        <PIfrom>9.1</PIfrom>
        <PIe1>1</PIe1>
        <PIe2>6</PIe2>
        <PIe3>122</PIe3>
        <PO />
      </PI>
      <PI>
        <PIqid>11</PIqid>
        <PIpid>450</PIpid>
        <PIpx>821</PIpx>
        <PIpy>144</PIpy>
        <PItext>Change the security level to Disabled. Is the customer able to browse the internet?</PItext>
        <PItype>Question</PItype>
        <PIfrom>9.2,8.2</PIfrom>
        <PIto>11.2,11.1</PIto>
        <PIc>281</PIc>
        <PO>
          <POoid>1</POoid>
          <POqid>11</POqid>
          <popid>450</popid>
          <POpx>-50</POpx>
          <POpy>70</POpy>
          <POtext>Yes</POtext>
          <POto>12</POto>
        </PO>
        <PO>
          <POoid>2</POoid>
          <POqid>11</POqid>
          <popid>450</popid>
          <POpx>50</POpx>
          <POpy>70</POpy>
          <POtext>No</POtext>
          <POto>14</POto>
        </PO>
      </PI>
      <PI>
        <PIqid>12</PIqid>
        <PIpid>450</PIpid>
        <PIpx>474</PIpx>
        <PIpy>186</PIpy>
        <PItext>Change the security level to Standard. Is the customer able to browse the internet now?</PItext>
        <PItype>Question</PItype>
        <PIfrom>11.1,8.3,8.4</PIfrom>
        <PIto>12.2,12.1</PIto>
        <PIc>283</PIc>
        <PO>
          <POoid>1</POoid>
          <POqid>12</POqid>
          <popid>450</popid>
          <POpx>-50</POpx>
          <POpy>70</POpy>
          <POtext>Yes</POtext>
          <POto>13</POto>
        </PO>
        <PO>
          <POoid>2</POoid>
          <POqid>12</POqid>
          <popid>450</popid>
          <POpx>50</POpx>
          <POpy>70</POpy>
          <POtext>No</POtext>
          <POto>14</POto>
        </PO>
      </PI>
      <PI>
        <PIqid>13</PIqid>
        <PIpid>450</PIpid>
        <PIpx>322</PIpx>
        <PIpy>278</PIpy>
        <PItext>Issue Resolved</PItext>
        <PItype>ExitPoint</PItype>
        <PIfrom>12.1</PIfrom>
        <PIe1>1</PIe1>
        <PIe2>6</PIe2>
        <PIe3>123</PIe3>
        <PO />
      </PI>
      <PI>
        <PIqid>14</PIqid>
        <PIpid>450</PIpid>
        <PIpx>645</PIpx>
        <PIpy>327</PIpy>
        <PItext>Ask the customer to perform a master reset. Does this resolve their issue?</PItext>
        <PItype>Question</PItype>
        <PIfrom>12.2,11.2</PIfrom>
        <PIto>14.2,14.1</PIto>
        <PIc>282</PIc>
        <PO>
          <POoid>1</POoid>
          <POqid>14</POqid>
          <popid>450</popid>
          <POpx>-50</POpx>
          <POpy>70</POpy>
          <POtext>Yes</POtext>
          <POto>16</POto>
        </PO>
        <PO>
          <POoid>2</POoid>
          <POqid>14</POqid>
          <popid>450</popid>
          <POpx>50</POpx>
          <POpy>70</POpy>
          <POtext>No</POtext>
          <POto>15</POto>
        </PO>
      </PI>
      <PI>
        <PIqid>15</PIqid>
        <PIpid>450</PIpid>
        <PIpx>768</PIpx>
        <PIpy>435</PIpy>
        <PItext>Faulty CPE</PItext>
        <PItype>ExitPoint</PItype>
        <PIfrom>14.2</PIfrom>
        <PIe1>1</PIe1>
        <PIe2>6</PIe2>
        <PIe3>124</PIe3>
        <PO />
      </PI>
      <PI>
        <PIqid>16</PIqid>
        <PIpid>450</PIpid>
        <PIpx>479</PIpx>
        <PIpy>420</PIpy>
        <PItext>Issue Resolved</PItext>
        <PItype>ExitPoint</PItype>
        <PIfrom>14.1</PIfrom>
        <PIe1>1</PIe1>
        <PIe2>6</PIe2>
        <PIe3>123</PIe3>
        <PO />
      </PI>
    </P>Thanks in advance.

  • Xml query help

    I have the XML below stored in a table in an XML field. I wish to query this record for the <HISTORY_BLOCK> data and get on record for each <row>. ie. I want to do something like
    Select
         extractvalue(detail, '/S12/HISTORY_BLOCK/RESULT’),
         extractvalue(detail, '/S12/HISTORY_BLOCK/ACTION’),
         extractvalue(detail, '/S12/HISTORY_BLOCK/DEVICE_TYPE’),
         extractvalue(detail, '/S12/HISTORY_BLOCK/RECORD_NUMBER’)
    FROM
         extract(table.field, '/S12/HISTORY_BLOCK’)
    which returns multiple records, one for each row. ie.
    TIME OUT,DISABLE,TASL,1,TASL,015F,2
    NOT SUCCESSFUL,DISABLE,TASL,1,TASL,015D,4
    NOT SUCCESSFUL,DISABLE,TASL,1,TASL,015C,6
    NOT SUCCESSFUL,DISABLE,ENDOFCAV,1,TASL,0157,8
    NOT SUCCESSFUL,DISABLE,ENDOFCAV,1,TASL,0155,10
    NOT SUCCESSFUL,DISABLE,ENDOFCAV,1,TASL,0154,12
    NOT SUCCESSFUL,DISABLE,TASL,1,TASL,0153,14
    NOT SUCCESSFUL,DISABLE,TASL,1,TASL,0152,16
    TIME OUT,DISABLE,TASL,1,TASL,0151,18
    NOT SUCCESSFUL,DISABLE,TASL,1,TASL,0150,20
    Reading the "Oracle9i Application Developer’s Guide - Fundamentals" manual, Table Functions, you can use a PL-SQL Table Function to transform the data and return multiple records from a single record in. As my XML data structure is not set but has many formats, I will need many PL-SQL functions to get the data out.
    Can you please check the Oracle resources to see whether there is a straight SQL answer to my requirements.
    Example of a single record of XML stored in the detail field.
    <S12>
    <ID_>ssapp010101125903468218634000</ID_>
    <oracle_tzr>EST</oracle_tzr>
    <HEADER_DATE_TIME>2005-09-05 16:59:06</HEADER_DATE_TIME>
    <NODE>EXEU</NODE>
    <EXCHANGE_STATUS>L705AA_64*W</EXCHANGE_STATUS>
    <RRN_NUMBER>00052</RRN_NUMBER>
    <COMMAND_NAME/>
    <MAIN_EXECUTION_RESULT>SYSTEM REPORT</MAIN_EXECUTION_RESULT>
    <COMMAND_CODE>AUDIT DISABLE</COMMAND_CODE>
    <REPORT_HEADER>REPORT ON DEPENDENT SBLS</REPORT_HEADER>
    <NETWORK_ADDRESS>H&apos;0150</NETWORK_ADDRESS>
    <SECURITY_BLOCK_TYPE>ACSW</SECURITY_BLOCK_TYPE>
    <SECURITY_BLOCK_NUMBER_RANGE>1</SECURITY_BLOCK_NUMBER_RANGE>
    <WAIT_FOR_TRAFFIC_CLEAR>0</WAIT_FOR_TRAFFIC_CLEAR>
    <GLOBAL_RESULT>ACTION FAILED</GLOBAL_RESULT>
    <HISTORY_BLOCK>
    <row>
    <RESULT>TIME OUT</RESULT>
    <ACTION>DISABLE</ACTION>
    <DEVICE_TYPE>TASL</DEVICE_TYPE>
    <NBR>1</NBR>
    <SECURITY_BLOCK_TYPE>TASL</SECURITY_BLOCK_TYPE>
    <NETWORK_ADDRESS>015F</NETWORK_ADDRESS>
    <RECORD_NUMBER>2</RECORD_NUMBER>
    </row>
    <row>
    <RESULT>NOT SUCCESSFUL</RESULT>
    <ACTION>DISABLE</ACTION>
    <DEVICE_TYPE>TASL</DEVICE_TYPE>
    <NBR>1</NBR>
    <SECURITY_BLOCK_TYPE>TASL</SECURITY_BLOCK_TYPE>
    <NETWORK_ADDRESS>015D</NETWORK_ADDRESS>
    <RECORD_NUMBER>4</RECORD_NUMBER>
    </row>
    <row>
    <RESULT>NOT SUCCESSFUL</RESULT>
    <ACTION>DISABLE</ACTION>
    <DEVICE_TYPE>TASL</DEVICE_TYPE>
    <NBR>1</NBR>
    <SECURITY_BLOCK_TYPE>TASL</SECURITY_BLOCK_TYPE>
    <NETWORK_ADDRESS>015C</NETWORK_ADDRESS>
    <RECORD_NUMBER>6</RECORD_NUMBER>
    </row>
    <row>
    <RESULT>NOT SUCCESSFUL</RESULT>
    <ACTION>DISABLE</ACTION>
    <DEVICE_TYPE>ENDOFCAV</DEVICE_TYPE>
    <NBR>1</NBR>
    <SECURITY_BLOCK_TYPE>TASL</SECURITY_BLOCK_TYPE>
    <NETWORK_ADDRESS>0157</NETWORK_ADDRESS>
    <RECORD_NUMBER>8</RECORD_NUMBER>
    </row>
    <row>
    <RESULT>NOT SUCCESSFUL</RESULT>
    <ACTION>DISABLE</ACTION>
    <DEVICE_TYPE>ENDOFCAV</DEVICE_TYPE>
    <NBR>1</NBR>
    <SECURITY_BLOCK_TYPE>TASL</SECURITY_BLOCK_TYPE>
    <NETWORK_ADDRESS>0155</NETWORK_ADDRESS>
    <RECORD_NUMBER>10</RECORD_NUMBER>
    </row>
    <row>
    <RESULT>NOT SUCCESSFUL</RESULT>
    <ACTION>DISABLE</ACTION>
    <DEVICE_TYPE>ENDOFCAV</DEVICE_TYPE>
    <NBR>1</NBR>
    <SECURITY_BLOCK_TYPE>TASL</SECURITY_BLOCK_TYPE>
    <NETWORK_ADDRESS>0154</NETWORK_ADDRESS>
    <RECORD_NUMBER>12</RECORD_NUMBER>
    </row>
    <row>
    <RESULT>NOT SUCCESSFUL</RESULT>
    <ACTION>DISABLE</ACTION>
    <DEVICE_TYPE>TASL</DEVICE_TYPE>
    <NBR>1</NBR>
    <SECURITY_BLOCK_TYPE>TASL</SECURITY_BLOCK_TYPE>
    <NETWORK_ADDRESS>0153</NETWORK_ADDRESS>
    <RECORD_NUMBER>14</RECORD_NUMBER>
    </row>
    <row>
    <RESULT>NOT SUCCESSFUL</RESULT>
    <ACTION>DISABLE</ACTION>
    <DEVICE_TYPE>TASL</DEVICE_TYPE>
    <NBR>1</NBR>
    <SECURITY_BLOCK_TYPE>TASL</SECURITY_BLOCK_TYPE>
    <NETWORK_ADDRESS>0152</NETWORK_ADDRESS>
    <RECORD_NUMBER>16</RECORD_NUMBER>
    </row>
    <row>
    <RESULT>TIME OUT</RESULT>
    <ACTION>DISABLE</ACTION>
    <DEVICE_TYPE>TASL</DEVICE_TYPE>
    <NBR>1</NBR>
    <SECURITY_BLOCK_TYPE>TASL</SECURITY_BLOCK_TYPE>
    <NETWORK_ADDRESS>0151</NETWORK_ADDRESS>
    <RECORD_NUMBER>18</RECORD_NUMBER>
    </row>
    <row>
    <RESULT>NOT SUCCESSFUL</RESULT>
    <ACTION>DISABLE</ACTION>
    <DEVICE_TYPE>TASL</DEVICE_TYPE>
    <NBR>1</NBR>
    <SECURITY_BLOCK_TYPE>TASL</SECURITY_BLOCK_TYPE>
    <NETWORK_ADDRESS>0150</NETWORK_ADDRESS>
    <RECORD_NUMBER>20</RECORD_NUMBER>
    </row>
    </HISTORY_BLOCK>
    <SECURITY_BLOCKS>

    Aussie_boy, there was a slight problem with the xml instance you posted, so i have taken the content only for the history blocks of your interest to make this sample.
    you can do it very well what you want using a combination of TABLE,XMLSEQUENCE and EXTRACT functions.
    SQL> create table xml_table(id number, xml_data xmltype)
      2  /
    Table created.
    SQL> insert into xml_table values(1,
      2  xmltype('<HISTORY_BLOCK>
      3   <row>
      4    <RESULT>TIME OUT</RESULT>
      5    <ACTION>DISABLE</ACTION>
      6    <DEVICE_TYPE>TASL</DEVICE_TYPE>
      7    <NBR>1</NBR>
      8    <SECURITY_BLOCK_TYPE>TASL</SECURITY_BLOCK_TYPE>
      9    <NETWORK_ADDRESS>015F</NETWORK_ADDRESS>
    10    <RECORD_NUMBER>2</RECORD_NUMBER>
    11   </row>
    12   <row>
    13    <RESULT>NOT SUCCESSFUL</RESULT>
    14    <ACTION>DISABLE</ACTION>
    15    <DEVICE_TYPE>TASL</DEVICE_TYPE>
    16    <NBR>1</NBR>
    17    <SECURITY_BLOCK_TYPE>TASL</SECURITY_BLOCK_TYPE>
    18    <NETWORK_ADDRESS>015D</NETWORK_ADDRESS>
    19    <RECORD_NUMBER>4</RECORD_NUMBER>
    20   </row>
    21   <row>
    22    <RESULT>NOT SUCCESSFUL</RESULT>
    23    <ACTION>DISABLE</ACTION>
    24    <DEVICE_TYPE>TASL</DEVICE_TYPE>
    25    <NBR>1</NBR>
    26    <SECURITY_BLOCK_TYPE>TASL</SECURITY_BLOCK_TYPE>
    27    <NETWORK_ADDRESS>015C</NETWORK_ADDRESS>
    28    <RECORD_NUMBER>6</RECORD_NUMBER>
    29   </row>
    30   <row>
    31    <RESULT>NOT SUCCESSFUL</RESULT>
    32    <ACTION>DISABLE</ACTION>
    33    <DEVICE_TYPE>ENDOFCAV</DEVICE_TYPE>
    34    <NBR>1</NBR>
    35    <SECURITY_BLOCK_TYPE>TASL</SECURITY_BLOCK_TYPE>
    36    <NETWORK_ADDRESS>0157</NETWORK_ADDRESS>
    37    <RECORD_NUMBER>8</RECORD_NUMBER>
    38   </row>
    39   <row>
    40    <RESULT>NOT SUCCESSFUL</RESULT>
    41    <ACTION>DISABLE</ACTION>
    42    <DEVICE_TYPE>ENDOFCAV</DEVICE_TYPE>
    43    <NBR>1</NBR>
    44    <SECURITY_BLOCK_TYPE>TASL</SECURITY_BLOCK_TYPE>
    45    <NETWORK_ADDRESS>0155</NETWORK_ADDRESS>
    46    <RECORD_NUMBER>10</RECORD_NUMBER>
    47   </row>
    48   <row>
    49    <RESULT>NOT SUCCESSFUL</RESULT>
    50    <ACTION>DISABLE</ACTION>
    51    <DEVICE_TYPE>ENDOFCAV</DEVICE_TYPE>
    52    <NBR>1</NBR>
    53    <SECURITY_BLOCK_TYPE>TASL</SECURITY_BLOCK_TYPE>
    54    <NETWORK_ADDRESS>0154</NETWORK_ADDRESS>
    55    <RECORD_NUMBER>12</RECORD_NUMBER>
    56   </row>
    57   <row>
    58    <RESULT>NOT SUCCESSFUL</RESULT>
    59    <ACTION>DISABLE</ACTION>
    60    <DEVICE_TYPE>TASL</DEVICE_TYPE>
    61    <NBR>1</NBR>
    62    <SECURITY_BLOCK_TYPE>TASL</SECURITY_BLOCK_TYPE>
    63    <NETWORK_ADDRESS>0153</NETWORK_ADDRESS>
    64    <RECORD_NUMBER>14</RECORD_NUMBER>
    65   </row>
    66   <row>
    67    <RESULT>NOT SUCCESSFUL</RESULT>
    68    <ACTION>DISABLE</ACTION>
    69    <DEVICE_TYPE>TASL</DEVICE_TYPE>
    70    <NBR>1</NBR>
    71    <SECURITY_BLOCK_TYPE>TASL</SECURITY_BLOCK_TYPE>
    72    <NETWORK_ADDRESS>0152</NETWORK_ADDRESS>
    73    <RECORD_NUMBER>16</RECORD_NUMBER>
    74   </row>
    75   <row>
    76    <RESULT>TIME OUT</RESULT>
    77    <ACTION>DISABLE</ACTION>
    78    <DEVICE_TYPE>TASL</DEVICE_TYPE>
    79    <NBR>1</NBR>
    80    <SECURITY_BLOCK_TYPE>TASL</SECURITY_BLOCK_TYPE>
    81    <NETWORK_ADDRESS>0151</NETWORK_ADDRESS>
    82    <RECORD_NUMBER>18</RECORD_NUMBER>
    83   </row>
    84   <row>
    85    <RESULT>NOT SUCCESSFUL</RESULT>
    86    <ACTION>DISABLE</ACTION>
    87    <DEVICE_TYPE>TASL</DEVICE_TYPE>
    88    <NBR>1</NBR>
    89    <SECURITY_BLOCK_TYPE>TASL</SECURITY_BLOCK_TYPE>
    90    <NETWORK_ADDRESS>0150</NETWORK_ADDRESS>
    91    <RECORD_NUMBER>20</RECORD_NUMBER>
    92   </row>
    93  </HISTORY_BLOCK>'))
    94  /
    1 row created.
    SQL>
    SQL> set linesize 200
    SQL> column result format a20
    SQL> column action format a10
    SQL> column device_type format a10
    SQL> column nbr format a5
    SQL> column security_block format a20
    SQL> column network_address format a10
    SQL> column record_number format a20
    SQL>
    SQL> select extractvalue(value(a), '/row/RESULT')          result
      2       , extractvalue(value(a), '/row/ACTION')          action
      3       , extractvalue(value(a), '/row/DEVICE_TYPE')     device_type
      4       , extractvalue(value(a), '/row/NBR')             nbr
      5       , extractvalue(value(a), '/row/SECURITY_BLOCK')  security_block
      6       , extractvalue(value(a), '/row/NETWORK_ADDRESS') network_address
      7       , extractvalue(value(a), '/row/RECORD_NUMBER')   record_number
      8  from xml_table
      9  , table(xmlsequence(extract(xml_Data, 'HISTORY_BLOCK/row')))  a
    10  where id =1
    11  /
    RESULT               ACTION     DEVICE_TYP NBR   SECURITY_BLOCK       NETWORK_AD RECORD_NUMBER                                                                                                         
    TIME OUT             DISABLE    TASL       1                          015F       2                                                                                                                     
    NOT SUCCESSFUL       DISABLE    TASL       1                          015D       4                                                                                                                     
    NOT SUCCESSFUL       DISABLE    TASL       1                          015C       6                                                                                                                     
    NOT SUCCESSFUL       DISABLE    ENDOFCAV   1                          0157       8                                                                                                                     
    NOT SUCCESSFUL       DISABLE    ENDOFCAV   1                          0155       10                                                                                                                    
    NOT SUCCESSFUL       DISABLE    ENDOFCAV   1                          0154       12                                                                                                                    
    NOT SUCCESSFUL       DISABLE    TASL       1                          0153       14                                                                                                                    
    NOT SUCCESSFUL       DISABLE    TASL       1                          0152       16                                                                                                                    
    TIME OUT             DISABLE    TASL       1                          0151       18                                                                                                                    
    NOT SUCCESSFUL       DISABLE    TASL       1                          0150       20                                                                                                                    
    10 rows selected.

  • SQL select query help

    I know this is a SQL question but I can't seem to figure this
    out. The below SQL query will run without error however it will
    output the company_name for every row which I dont want.
    So basicly it currently outputs like this now:
    company_name - apple
    company_name - dell
    BUT want it to output like this:
    company_name - apple,dell
    MY CURRENT QUERY:
    SELECT d.disputeid, t.company_name, t.tlid, t.type,
    l.description
    FROM member_disputes d, member_tradeline t, letters l
    WHERE d.fk_tlid = t.tlid
    AND d.fk_letterid = l.letterid
    AND d.fk_memberid = #GetAuthUser()#
    Any help much appreciated

    quote:
    Originally posted by:
    LionelR
    I know this is a SQL question but I can't seem to figure this
    out. The below SQL query will run without error however it will
    output the company_name for every row which I dont want.
    So basicly it currently outputs like this now:
    company_name - apple
    company_name - dell
    BUT want it to output like this:
    company_name - apple,dell
    MY CURRENT QUERY:
    SELECT d.disputeid, t.company_name, t.tlid, t.type,
    l.description
    FROM member_disputes d, member_tradeline t, letters l
    WHERE d.fk_tlid = t.tlid
    AND d.fk_letterid = l.letterid
    AND d.fk_memberid = #GetAuthUser()#
    Any help much appreciated
    Suddenly a light bulb illuminated over my head.
    <cfouput>
    company_name - #ValueList(yourquery.company_name)#
    </cfoutput>
    If that doesn't work, either change this, "t.company_name" to
    "company_name" or "t.company_name as company_name".
    I can't believe none of us thought of this earlier.

  • SQL SELECT Query Help   ..Please its very Urgent!!

    Hi All,
    I am having Oracle Database whice is storing 1000's of records daily.
    I need to select some information based on date and time.
    I am having two coloumns for Date and time. The first column(testDate) of type Date stores date as MM/DD/YY format and the second column(testTime)of type Numeric stores the time in seconds.
    The Example data is :
    testDate ------=-- testTime
    11/12/2002 --- 35000
    11/12/2002 --- 43000
    11/12/2002 --- 45000
    11/12/2002 --- 75000
    11/13/2002 --- 2000
    11/13/2002 --- 3500
    11/13/2002 --- 4300
    11/13/2002 --- 9800
    11/13/2002 --- 23000
    11/14/2002 --- 5000
    11/14/2002 --- 10000
    11/14/2002 --- 15000
    How can i write a SELECT Query to get the records of specific date and seconds to next day specific date and seconds.I mean i want all the records between 11/12/2002 --- 43000 seconds to 11/14/2002 --- 1000 seconds.
    If any one helps me in this regard iam very thank full to them.Its very urgent for me.
    Thanks

    Hi m7nra,
    I used the query as
    SELECT * FROM table
    WHERE testDate + (testTime/(24*60*60)) BETWEEN TO_DATE('MM/DD/YYYY','12.11.2002') AND TO_DATE('MM/DD/YYYY','14.11.2002')
    its giving DATE FORMAT NOT RECOGNIZED error.
    The Example data is :
    testDate ------=-- testTime
    11/12/2002 --- 35000
    11/12/2002 --- 43000
    11/12/2002 --- 45000
    11/12/2002 --- 75000
    11/13/2002 --- 2000
    11/13/2002 --- 3500
    11/13/2002 --- 4300
    11/13/2002 --- 9800
    11/13/2002 --- 23000
    11/14/2002 --- 5000
    11/14/2002 --- 10000
    11/14/2002 --- 15000
    infact i need all the records between 11/12/2002 --- 43000 seconds to 11/14/2002 --- 1000 seconds.
    Please help me to find a full query beacuse iam very new to Oracle.
    Thanks,
    S R Mannava

  • SQL pivot query help

    HUM ADG DYS (NIA, SIM, TRC, TRX) SMALL BRANDS (LUP, KAL,CRN,LPP,SYN)
    MON TUE WED THURS FRI MON TUE WED THURS FRI MON TUE WED THURS FRI MON TUE WED THURS FRI
    VENDOR
    INT
    QUAN
    STER
    LASH
    OSP
    HIB
    PROD
    I’d like to put together a query to populate the tables above,like count of recods for each vendor for each brand with the criteria for selecting within one week.
    Here vendor_cd(INT,QUAN,STER,...etc),brand_cd(HUM,ADG,NIA,SIM,..eyc).we are extracting the details from file detail table whose column are like FILE_ID,FILE_RECEIPT_TS,REC_INSERT_TS,VENDOR_CD,BRAND_CD,RECORD_COUNT.
    Edited by: ASHWINI89 on Mar 21, 2013 8:33 PM

    Welcome to the forum!!
    Please consider the following when you post a question. This would help us help you better
    1. New features keep coming in every oracle version so please provide Your Oracle DB Version to get the best possible answer.
    You can use the following query and do a copy past of the output.
    select * from v$version 2. This forum has a very good Search Feature. Please use that before posting your question. Because for most of the questions
    that are asked the answer is already there.
    3. We dont know your DB structure or How your Data is. So you need to let us know. The best way would be to give some sample data like this.
    I have the following table called sales
    with sales
    as
          select 1 sales_id, 1 prod_id, 1001 inv_num, 120 qty from dual
          union all
          select 2 sales_id, 1 prod_id, 1002 inv_num, 25 qty from dual
    select *
      from sales 4. Rather than telling what you want in words its more easier when you give your expected output.
    For example in the above sales table, I want to know the total quantity and number of invoice for each product.
    The output should look like this
    Prod_id   sum_qty   count_inv
    1         145       2 5. When ever you get an error message post the entire error message. With the Error Number, The message and the Line number.
    6. Next thing is a very important thing to remember. Please post only well formatted code. Unformatted code is very hard to read.
    Your code format gets lost when you post it in the Oracle Forum. So in order to preserve it you need to
    use the {noformat}{noformat} tags.
    The usage of the tag is like this.
    <place your code here>\
    7. If you are posting a *Performance Related Question*. Please read
       {thread:id=501834} and {thread:id=863295}.
       Following those guide will be very helpful.
    8. Please keep in mind that this is a public forum. Here No question is URGENT.
       So use of words like *URGENT* or *ASAP* (As Soon As Possible) are considered to be rude.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • SQL xml query problems

    Hello,
    I am trying to query a database column containing xml. How my problem is when I display my query on the page the data is not being shown properly.
    The data in the database is like this:
    <P><tag1>2003/05/22 11:01:34</tag1><tag2>2003/05/22</tag2><tag3>11:01:34</tag3><tag4></tag4>.......
    However all that is returned is on the jsp page
    2003/05/22 11:01:34<tag2>2003/05/22<tag3>11:01:34..............
    i.e closing tags missing and empty pairs not shown at all.
    My query is a simple
    String sqlQuery="select * from table;
    rs = stmt.executeQuery (sqlQuery);
    rs.next();
    out.print(rs.getString(1));
    Can anyone suggest why the data stored in the column is being truncated and how I can prevent this.
    Many thanks in advance
    Les,

    Surely this is because the browser is interpretting the tags as HTML tags? Do a "view source" on the page and it should be right.
    Otherwise, you will have to store the query in the DB with escapt characters before the <'s

  • SQL recursive query help

    Hi All,
    I have below table
    IT_Terms_First_Date
    IT_Terms_Last_Date
    DI_Debt_Num
    IT_Terms_Seq_Num
    200501
    201101
    1000
    131
    200512
    203412
    1001
    131
    200503
    204209
    1003
    131
    200507
    201001
    1004
    131
    200510
    202710
    1005
    131
    200506
    202412
    10020
    131
    197910
    198310
    257000
    101
    198009
    202909
    298000
    101
    198101
    202908
    298000
    103
    198105
    202910
    298000
    104
    199109
    201309
    578000
    101
    199204
    201110
    600000
    101
    198009
    201010
    298010
    101
    198105
    204010
    298010
    104
    201011
    202909
    298010
    103
    I need to check whether my DI_Debt_Num having Ovelaping or not for each DI_Debt_Num,
    at this moment we are checking each row in loop and usnig function
    exec @Overlap1=[DffMonths] @ITtermsLD,@ITtermsNextFD
    exec @Overlap2=[DffMonths] @ITtermsFD,@ITtermsNextFD
    exec @Overlap3=[DffMonths] @ITtermsFD,@ITtermsNextLD
    if(@Overlap1>0 and (@Overlap2<=0 OR @Overlap3<0))
    BEGIN
    SET @CheckOverlap=1
    END
    here @ITtermsLD is the IT_Terms_Last_Date of the current DI_Debt_Num,@ITtermsNextFD is the IT_Terms_First_Date of the next row. @ITtermsFD is the IT_Terms_First_Date of the current month
    if we consider the 298000 DI_Debt_Num we have 3 IT_Terms_Seq_Num 101,103,104
    in this senario we need to check only the first 2 rows from that itself we can identify it is overlapped ,but when we consider the 298010 we need to check all 3 IT_Terms_Seq_Num 101,103,104 if we consider first two rows 101 & 103 it is not overlapped.Then
    we have to check first row with 3rd row ie 104 and it is overlapped.We are checking the overlap senario for DI_Debt_Num having multipple IT_Terms_Seq_Num rows
    Some situation first row may not be overlapped with other rows .Then we have to check the 2nd row with the next rows in the same way we are doing for first row
    My aim is to covert this looping method to a select query to improve my query performance
    Thanks in advance
    Roshan

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. You have no idea,
    do you? Temporal data should use ISO-8601 formats. You failed again! I will guess that your dates are months. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. 
    >> I have below table <<
    This is not a table! Where is the DDL?  This picture has no name. Not even a name!! There is no “seq_nbr” in RDBMS; it has to be a “<something in particular>_seq” and there are no duplicates in a sequence. 
    My guess is that each di_debt_nbr has a sequence within its range. I will call it the “foobar_seq” for lack of a name. 
    My next guess is that your dates are really months and you do not know about using a report period table. This idiom gives a name to a range of dates that is common to the entire enterprise. 
    CREATE TABLE Something_Report_Periods
    (something_report_name CHAR(10) NOT NULL PRIMARY KEY
       CHECK (something_report_name LIKE <pattern>), 
     something_report_start_date DATE NOT NULL, 
     something_report_end_date DATE NOT NULL, 
      CONSTRAINT date_ordering
        CHECK (something_report_start_date <= something_report_end_date), 
    etc);
    These report periods can overlap or have gaps. I like the MySQL convention of using double zeroes for months and years, That is 'yyyy-mm-00' for a month within a year and 'yyyy-00-00' for the whole year. The advantages are that it will sort with the ISO-8601
    data format required by Standard SQL and it is language independent. The pattern for validation is '[12][0-9][0-9][0-9]-00-00' and '[12][0-9][0-9][0-9]-[01][0-9]-00'
    Here is another guess at what you want, if you knew what a table is: 
    CREATE TABLE DI_Debts
    (it_terms_first_date CHAR(10) NOT NULL
       REFERENCES Report_Period (month_name), 
     it_terms_last_date CHAR(10) NOT NULL
       REFERENCES Report_Period (month_name), 
     CHECK (it_terms_first_date <= it_terms_last_date), 
     di_debt_nbr INTEGER NOT NULL, 
     foobar_seq INTEGER NOT NULL, 
     PRIMARY KEY (di_debt_nbr, foobar_seq));
    INSERT INTO DI_Debts
    VALUES
    ('2005-01-00', '2011-01-00', 1000, 1), 
    ('2005-12-00', '2034-12-00', 1001, 1), 
    ('2005-03-00', '2042-09-00', 1003, 1), 
    ('2005-07-00', '2010-01-00', 1004, 1), 
    ('2005-10-00', '2027-10-00', 1005, 1), 
    ('2005-06-00', '2024-12-00', 100201, 1), 
    ('1979-10-00', '1983-10-00', 257000, 1), 
    ('1980-09-00', '2029-09-00', 2980001, 1), 
    ('1981-01-00', '2029-08-00', 298000, 1), 
    ('1981-05-00', '2029-10-00', 298000, 2), 
    ('1991-09-00', '2013-09-00', 578000, 1), 
    ('1992-04-00', '2011-10-00', 600000, 1), 
    ('1980-09-00', '2010-10-00', 298010, 1), 
    ('1981-05-00', '2040-10-00', 298010, 2), 
    ('2010-11-00', '2029-09-00', 298010, 3);
    I need to check whether my DI_Debt_nbr are overlapping or not for each DI_Debt_nbr, 
    >> at this moment we are checking each row in loop and using function 
    exec @Overlap1=[DffMonths] @IttermsLD, @ITtermsNextFD;
    exec @Overlap2=[DffMonths] @IttermsFD, @ITtermsNextFD;
    exec @Overlap3=[DffMonths] @IttermsFD, @ITtermsNextLD; <<
    And you were too rude to post the code for these functions! You write SQL with assembly language flags! We do not do that!  We also would use a CASE expression, and not IF-THEN control flow in SQL.  
    Did you know that ANSI/ISO Standard SQL has a temporal <overlaps predicate>? Notice the code to handle NULLs and the ISO half-open interval model. 
    (start_date_1 > start_date_2 
     AND NOT (start_date_1 >= end_date_2 
                AND end_date_1 >= end_date_2)) 
    OR (start_date_2 > start_date_1 
        AND NOT (start_date_2 >= end_date_1 
                 AND end_date_2 >= end_date_1)) 
    OR (start_date_1 = start_date_2 
        AND (end_date_1 <> end_date_2 OR end_date_1 = end_date_2)) 
    I tend to prefer the use of a calendar table. NULLs return an empty set, as above. 
    EXISTS 
    ((SELECT cal_date FROM Calendar 
       WHERE cal_date BETWEEN start_date_1 AND end_date_1)
     INTERSECT
     (SELECT cal_date FROM Calendar 
       WHERE cal_date BETWEEN start_date_2 AND end_date_2))
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • SQL Search Query - HELP!

    I'm trying to figure out which table/column it is that holds a particular value from the application I am using.
    I need a SQL query that will interrogate the database based on the value of a particur colunmn so that it returns and column_name that has a value called 'www.google.com' contained in it and the associated table_name
    Any ideas?
    Thanks!

    One of Michaels examples...
    michaels>  var val varchar2(5)
    michaels>  exec :val := 'as'
    PL/SQL procedure successfully completed.
    michaels>  select distinct substr (:val, 1, 11) "Searchword",
                    substr (table_name, 1, 14) "Table",
                    substr (t.column_value.getstringval (), 1, 50) "Column/Value"
               from cols,
                    table
                       (xmlsequence
                           (dbms_xmlgen.getxmltype ('select ' || column_name
                                                    || ' from ' || table_name
                                                    || ' where upper('
                                                    || column_name
                                                    || ') like upper(''%' || :val
                                                    || '%'')'
                                                   ).extract ('ROWSET/ROW/*')
                       ) t
    --        where table_name in ('EMPLOYEES', 'JOB_HISTORY', 'DEPARTMENTS')
           order by "Table"Example of it working...
    SQL> ed
    Wrote file afiedt.buf
      1  select distinct substr (table_name, 1, 14) "Table",
      2                  substr (t.column_value.getstringval (), 1, 50) "Column/Value"
      3             from cols,
      4                  table
      5                     (xmlsequence
      6                         (dbms_xmlgen.getxmltype ('select ' || column_name
      7                                                  || ' from ' || table_name
      8                                                  || ' where upper('
      9                                                  || column_name
    10                                                  || ') like upper(''%' || 'SCOTT'
    11                                                  || '%'')'
    12                                                 ).extract ('ROWSET/ROW/*')
    13                         )
    14                     ) t
    15          where table_name in ('EMP', 'DEPT')
    16*        order by "Table"
    SQL> /
    Table          Column/Value
    EMP            <ENAME>SCOTT</ENAME>
    SQL>

  • Intermedia - XML query help

    I do the following at a sqlplus command window
    create table xml (
    id number,
    xmltext clob);
    insert into xml values (1,'<a><b><c>steve</c></b></a>');
    exec ctx_ddl.create_section_group ('mysectiongroup','xmlsectiongroup');
    exec ctx_ddl.add_zone_section('mysectiongroup','a','a');
    exec ctx_ddl.add_zone_section('mysectiongroup','b','b');
    exec ctx_ddl.add_field_section('mysectiongroup','c','c');
    create index my_index on xml (xmltext) indextype is ctxsys.context parameters('section group mysectiongroup');
    select count(*) from xml where contains (xmltext,
    '(steve within ( c within (b within a)))');
    and count = 0, How can I get this to work ?

    Seems the insert left out my tags
    should look like this with lb = < and rb = >
    insert into xml values (1,"'lb a rb lb b rb lb c rb steve lb/c rb lb/b rb lb/a rb'");

  • SQL Join query help

    Hello,
    I have two select statements as
    Query 1 : Select col1,col2,col3,col4,value_a from table_1
    Query 2: Select col1,col2,col3,col4,value_b from table_2
    I want to join these two select statement to get below result.
    col1 col2 col3 col4 value_a value_b
    Scenario 1: Both query fecth the result
    Result of query 1:
    Col1 Col 2 Col3 Col4 Value_a
    1 TK TL TM 100
    Result of query 2:
    Col1 Col 2 Col3 Col4 Value_b
    1 TK TL TM 200
    Ultimate join result should be
    Col1 Col 2 Col3 Col4 Value_a value_b
    1 TK TL TM 100 200
    Scenario 2: Only query 1 fetches the result
    Result of query 1:
    Col1 Col 2 Col3 Col4 Value_a
    1 TN TO TP 300
    Result of query 2:
    Col1 Col 2 Col3 Col4 Value_b
    Ultimate join result should be
    Col1 Col 2 Col3 Col4 Value_a value_b
    1 TN TO TP 300 0
    Scenario 3: Only query 2 fetches the result
    Result of query 1:
    Col1 Col 2 Col3 Col4 Value_a
    Result of query 2:
    Col1 Col 2 Col3 Col4 Value_b
    1 TN TO TP 300
    Ultimate join result should be
    Col1 Col 2 Col3 Col4 Value_a value_b
    1 TN TO TP 0 300
    How should I join these?

    Because you want a FULL OUTER JOIN .
    select
       t1.*, t2.*
    from
       table_1 t1
       full outer join table_2 t2
    on
             t2.col1 = t1.col1
       and   t2.col2 = t1.col2
       and   t2.col3 = t1.col3
       and   t2.col4 = t1.col4
    )Please read the FAQ and learn how to post questions, so you can format your code, etc...
    http://wiki.oracle.com/page/Oracle+Discussion+Forums+FAQ

  • SQL server Query help

    I have four table like below:
    CREATE TABLE Party ( PartyID int identity(1,1)not null, PartyRegisteredDate datetime, MemberNo varchar(16), SubsNo varchar(9), PerNo varchar(2) )
    CREATE TABLE Contract ( ContractID int identity(1,1)not null, PartyID int, MemberNo varchar(16), SubsNo varchar(9), PerNo varchar(2) , ContractStartDate datetime, ContractEndDate datetime)
    CREATE TABLE IndividualContract ( IndContractID int identity(1,1)not null, ContractID int, PartyID int, MemberNo varchar(16), SubsNo varchar(9), PerNo varchar(2) ,ContractStartDate datetime, ContractEndDate datetime )
    CREATE TABLE Customer ( CustomerID int, IndContractID int, ContractID int, MemberNo varchar(16), SubsNo varchar(9), PerNo varchar(2))
    The business Key is MemberNo, SubsNo, PerNo in all the 4 tables.
    Contract table has PartyID as foreignKey from Party table
    IndividualContract table has ContractID,PartyID as foreignKeys from Party table and Contract table.
    Customer table has IndContractID,ContractID as foreignKeys from IndividualContract table.
    CustomerID in Customer table is nothing but PartyID.
    IndividualContract and Customer tables should be one-one.
    --Below is the source data in #Source table
    Create Table #Source (MemberNo varchar(16), SubsNo varchar(9), PerNo varchar(2),PartyRegisteredDate datetime, ContractStartDate datetime, ContractEndDate datetime)
    Insert into #Source
    Select '054911', '079548709', '01', '2002-09-01 00:00:00.000', '2012-08-01 00:00:00.000', '9999-12-31 00:00:00.000' union all
    Select '824212', '091547708', '01', '1987-07-14 00:00:00.000', '1987-07-14 00:00:00.000', '2010-09-01 00:00:00.000' union all
    Select '864211', '041609336', '01', '1993-01-01 00:00:00.000', '1999-03-01 00:00:00.000', '1999-12-31 00:00:00.000' union all
    Select '864212', '113523275', '01', '1993-01-01 00:00:00.000', '1998-06-01 00:00:00.000', '1999-12-31 00:00:00.000' union all
    Select '824212', '079548709', '02', '1987-07-14 00:00:00.000', '2010-09-01 00:00:00.000', '2010-09-01 00:00:00.000' union all
    Select '864211', '113523275', '02', '1993-01-01 00:00:00.000', '1999-03-01 00:00:00.000', '1999-12-31 00:00:00.000' union all
    Select '864212', '041609336', '02', '1993-01-01 00:00:00.000', '1998-05-01 00:00:00.000', '1999-12-31 00:00:00.000' union all
    Select '864212', '091547708', '03', '1993-01-01 00:00:00.000', '1998-06-01 00:00:00.000', '1999-12-31 00:00:00.000' union all
    Select '867616', '041609336', '03', '1993-04-05 00:00:00.000', '1998-05-01 00:00:00.000', '1999-12-31 00:00:00.000' union all
    Select '867616', '113523275', '03', '1993-04-05 00:00:00.000', '1998-06-01 00:00:00.000', '1999-12-31 00:00:00.000'
    This source data should go to the above 4 tables.
    But the requirement is:
    1. For one MemberNo there should be only one row in Party table. So in my case ,the party table should have only 5 rows like below.
    PartyID PartyRegisteredDate MemberNo SubsNo PerNo
    1 1987-07-14 00:00:00.000 824212 091547708 01
    2 1993-01-01 00:00:00.000 864211 041609336 01
    3 1993-01-01 00:00:00.000 864212 113523275 01
    4 1993-04-05 00:00:00.000 867616 041609336 03
    5 2002-09-01 00:00:00.000 054911 079548709 01
    2. The contract table should have only records with PerNo='01' for one MemberNo.So in my case this table should have like below.
    ContractID PartyID MemberNo SubsNo PerNo ContractStartDate ContractEndDate
    1 1 824212 091547708 01 1987-07-14 00:00:00.000 2010-09-01 00:00:00.000
    2 2 864211 041609336 01 1993-01-01 00:00:00.000 1999-12-31 00:00:00.000
    3 3 864212 113523275 01 1993-01-01 00:00:00.000 1999-12-31 00:00:00.000
    4 5 054911 079548709 01 2002-09-01 00:00:00.000 9999-12-31 00:00:00.000
    3. The IndividualContract and Customer should have all the records from #Source table, as IndividualContract and Customer tables are one-one.
    4. IndivuidialContract table should look like below:
    Here the ContractID is based on the SubsNo from Contract table.
    IndContractID ContractID PartyID MemberNo SubsNo PerNo ContractStartDate ContractEndDate
    1 1 1 824212 091547708 01 1987-07-14 00:00:00.000 1988-09-30 00:00:00.000
    2 4 1 824212 079548709 02 2010-09-01 00:00:00.000 2010-09-01 00:00:00.000
    3 2 2 864211 041609336 01 1999-03-01 00:00:00.000 1999-03-01 00:00:00.000
    4 3 2 864211 113523275 02 1999-03-01 00:00:00.000 1999-12-31 00:00:00.000
    5 3 3 864212 113523275 01 1998-06-01 00:00:00.000 1999-12-31 00:00:00.000
    6 2 3 864212 041609336 02 1998-05-01 00:00:00.000 1998-05-31 00:00:00.000
    7 1 3 864212 091547708 03 1998-06-01 00:00:00.000 1998-06-01 00:00:00.000
    8 2 4 867616 041609336 03 1998-05-01 00:00:00.000 1998-05-01 00:00:00.000
    9 3 4 867616 113523275 03 1998-06-01 00:00:00.000 1999-12-31 00:00:00.000
    10 4 5 054911 079548709 01 2012-08-01 00:00:00.000 9999-12-31 00:00:00.000
    5. Customer table should look like below:
    IndContractId and ContractID for this table comes from IndivuidialContract table.
    CustomerID IndContractID ContractID MemberNo SubsNo PerNo
    1 1 1 824212 091547708 01
    1 2 4 824212 079548709 02
    2 3 2 864211 041609336 01
    2 4 3 864211 113523275 02
    3 5 3 864212 113523275 01
    3 6 2 864212 041609336 02
    3 7 1 864212 091547708 03
    4 8 2 867616 041609336 03
    4 9 3 867616 113523275 03
    5 10 4 054911 079548709 01

    Your DDL is wrong. No keys, NO way to have keys, singular table names (I am sorry you have only one customer), etc. You do not know the syntax for insertion, etc. You have no idea how to do a data model. Why is a party use a physical table property as an
    identifier?? Did you know about the DATE data type? 
    Why did you use IDENTITY? Why is the count of physical insertions an attribute of a contract in your mind? This is as silly as identifying a car by the parking space number in one garage! But not the VIN. 
    CREATE TABLE Parties
    (party_duns CHAR(9) NOT NULL PRIMARY KEY, 
     party_registration_date DATE DEFAULT CURRENT TIMESTAMP NOT NULL, 
     member_nbr CHAR(16) NOT NULL, 
     subs_nbr CHAR(9) NOT NULL, 
     per_nbr CHAR(2) NOT NULL NOT NULL);
    Do you know what a DUNS is and why it is a valid identifier for a party in a contract?  
    CREATE TABLE Contracts
    (contract_id CHAR(25) NOT NULL PRIMARY KEY, 
     party_duns CHAR(9) NOT NULL
      REFERENCES  Parties (party_duns), 
     member_nbr CHAR(16) NOT NULL, 
     subs_nbr CHAR(9) NOT NULL, 
     per_nbr CHAR(2) NOT NULL, 
     contract_start_date DATE DEFAULT CURRENT TIMESTAMP NOT NULL, 
     contract_end_date DATE, 
     CHECK (contract_start_date < contract_end_date));
    Why did you put the DRI in a useless narrative?? I guessed at one. 
    CREATE TABLE Individual_Contracts
    (ind_contract_id CHAR(25) NOT NULL,
     contract_id CHAR(25) NOT NULL, 
     party_duns CHAR(9) NOT NULL, 
     member_nbr CHAR(16) NOT NULL,
     subs_nbr CHAR(9) NOT NULL,
     per_nbr CHAR(2) NOT NULL, 
     contract_start_date DATE DEFAULT CURRENT TIMESTAMP NOT NULL,
     contract_end_date DATE)
    CREATE TABLE Customers
    ( CustomerID  int, 
     indcontract_id int,
     contract_id  CHAR(25) NOT NULL,
     member_nbr CHAR(16) NOT NULL,
     subs_nbr CHAR(9) NOT NULL,
     per_nbr CHAR(2) NOT NULL)
    >> The business Key is member_nbr, subs_nbr, per_nbr in all the 4 tables. <<
    That is a design flaw. A key should locate one and only one entity in the schema. But you have split the entity over many tables. 
    >> Contract table has party_id as foreign Key from Parties table <<
    Where is the DDL for this??? 
    >> IndividualContract table has contract_id, party_id as foreignKeys from Parties table and Contract table. <<
    Where is the DDL for this??? 
    >> Customer table has Indcontract_id, contract_id as foreignKeys from IndividualContract table. <<
    Where is the DDL for this??? 
    >> CustomerID in Customer table is nothing but party_id. <<
    Redundancy is the reason we moved from files to DBs. 
    >> IndividualContract and Customer tables should be one-one. <<
    Where is the DDL for this??? 
    You almost know what you are doing , which is a nice change from most postings here. But I cannot donate $$$$ hours of consulting to you. For example, why is an individual contract totally different form a mere contract? Etc. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

Maybe you are looking for