XMLAGG problem

We have stored procedure which creates a long string of XML (which is stored as a clob in the database column)using the xmlAGG and XMLElement. The stored proc calls sub functions which all run fine when called individually however when called collectively from the stored proc the xml generated appears corrupted with a section missing and always gets corrupted at the same point i.e. a sub function pulls back a number of installment records - when we try to retrieve more than 4 records 1016 bytes the result gets corrupted. We are using oracle 10g with the latest patches 10.0.2.0.2 and running it on a linux - we also tried it from a windows platform but get the same problem. We know its not the code that is the problem because it works fine from a linux machine. Has anyone else experience similar problems or have any ideas on how to resolve?

Sorry yes noticed the typo in my original post. It occurs on both linux and windows but not apparently AIX. the data is accumulated into a big XML ELEMENT using XMLAGG and XMLELEMENT and XMLTYPE. when all data required has been accumulated a toClob is performed which is the format it is stored in database as. Originally we used a 9i database on windows and had no problems at all with the exact same code but customer wishes to upgrade to 10g which we have had problems with but they have not had problems with 10g installed in AIX box.
Here is the stored procedure :
PROCEDURE LTR_CUSTOMER_STATEMENT_SP
/*======================================================================
** Inputs
**=====================================================================*/
IN_PAYMENT_PLAN_ID IN VARCHAR2, -- Identifies the Payment Plan
IN_FROM_DATE IN VARCHAR2, -- Lower bound for installments,
-- payments and broker fees
IN_UNTIL_DATE IN VARCHAR2, -- Upper bound for installments and payments
/*=======================================================================
** Input / Outputs
**=====================================================================*/
RESULT_SET_LIST IN OUT KPK_PPP_DATATYPES.letter_data_result_list,
-- returnedXML in result set
SUCCESS OUT NUMBER -- Success value
AS
/*=======================================================================
** Local vars
**=====================================================================*/
pay_plan_id_p INTEGER; -- Holds CRN converted
from_date_p DATE; -- Holds from date converted
until_date_p DATE; -- Holds until date converted
li_agency_id_p INTEGER; -- holds the agency id of the latest loan on the payment plan
BEGIN
/*=======================================================================
** Assign local vars
**=====================================================================*/
pay_plan_id_p := TO_NUMBER(IN_PAYMENT_PLAN_ID);
from_date_p := TO_DATE(IN_FROM_DATE, 'DD/MM/YYYY');
until_date_p := TO_DATE(IN_UNTIL_DATE, 'DD/MM/YYYY');
/*=======================================================================
** Get agency id
**=====================================================================*/
SELECT agency_id INTO li_agency_id_p
     FROM (SELECT agency_id
     FROM LOAN l
     WHERE l.payment_plan_id = IN_PAYMENT_PLAN_ID
     ORDER BY l.created_on DESC)
     WHERE ROWNUM = 1;
BEGIN
OPEN RESULT_SET_LIST FOR
SELECT XMLElement( "LETTER",
/*==============================================================
** Add the 'ALL_LETTERS' node
**==============================================================*/
( SELECT XML_RETURN_BLOCK FROM LTR_SUB_ALL_LETTER_INFO_V
WHERE PAYMENT_PLAN_ID = pay_pln.ID),
/*======================================================
** Add the 'HIB_COMPANY_INFO' node
**=====================================================*/
( SELECT XML_RETURN_BLOCK
FROM LTR_SUB_HIB_COMPANY_INFO_V
WHERE AGENCY_ID = li_agency_id_p),
/*=========================================================
** Add the 'CONTACT INFORMATION' node
**========================================================*/
XMLElement ( "CONTACT_INFORMATION",
( SELECT XML_RETURN_BLOCK
FROM LTR_SUB_CUST_CONTACT_INFO_V
WHERE PAYMENT_PLAN_ID = pay_pln.ID),
( SELECT XML_RETURN_BLOCK
FROM LTR_SUB_HIB_CONTACT_INFO_V
WHERE AGENCY_ID = li_agency_id_p),
( SELECT XML_RETURN_BLOCK
FROM LTR_SUB_BROKER_CONTACT_INFO_V
WHERE PAYMENT_PLAN_ID = pay_pln.ID)
), -- End XMLElement
/*==============================================
** Add the 'PLAN DETAILS' node
**=============================================*/
LTR_SUB_PLAN_INFO_SP
(pay_pln.ID, from_date_p, until_date_p, 'N'),
/*===============================================
** Add the 'POLICY DETAILS' node
**==============================================*/
LTR_SUB_POLICY_INFO_SP
(pay_pln.ID, from_date_p, until_date_p, 'N'),
/*===============================================
** Add the 'BANK DETAILS' node
**==============================================*/
(SELECT XML_RETURN_BLOCK
FROM LTR_SUB_BANK_DETAILS_V
WHERE PAYMENT_PLAN_ID = pay_pln.ID),
/*===============================================
** Add the 'Originator identificatin number' node
**==============================================*/
( SELECT XML_RETURN_BLOCK
FROM LTR_SUB_ORIGINATOR_NUMBER_V),
/*===============================================
** Add the 'Refund Originator number' node
**==============================================*/
( SELECT XML_RETURN_BLOCK
FROM LTR_SUB_REFUND_ORIG_NUM_V),
/*===============================================
** Add the ''BROKER FEES' node
**==============================================*/
LTR_SUB_BROKER_FEES_SP (pay_pln.ID, from_date_p)
).getClobVal() -- End Main XMLElement (return as CLOB)
FROM PAYMENT_PLAN pay_pln
WHERE pay_pln.ID = pay_plan_id_p;
/*=======================================================================
** Handle any exceptions
**=====================================================================*/
EXCEPTION
WHEN NO_DATA_FOUND THEN
SUCCESS := -1;
RETURN;
WHEN OTHERS THEN
SUCCESS := SQLCODE;
RETURN;
END;
/*==========================================================================
** Set the success value
**========================================================================*/
SUCCESS := 0;
END;
This is the sub function which works when called on its own but not cumulatively with everything else:
CREATE OR REPLACE FUNCTION LTR_SUB_PLAN_INFO_SP
IN_PAYMENT_PLAN_ID in INTEGER, -- Payment Plan identifier
IN_FROM_DATE in DATE, -- Lower date range for payment date
IN_UNTIL_DATE in DATE, -- Upper date range for payment date
IN_EXCLUDE_PAID_PAYMENTS in CHAR -- Exclude payments that have already been paid?
RETURN XMLType IS XML_RETURN_BLOCK XMLType;
BEGIN
/*==============================================================================
** Get the payment plan for the supplied ID
**=============================================================================*/
SELECT XMLElement( "PLAN_INFORMATION",
XMLForest ( plan.CUSTOMER_ID AS CRN,
plan.OVERPAYMENT AS OVERPAYMENT_AMT,
                                        KPG_UTILS.NUM_LOANS_BEFORE_MIGRATION(IN_PAYMENT_PLAN_ID) AS NUM_LOANS_B4_MIGRATION
                                        SELECT COUNT(*)
                                        FROM PLAN_INSTAL_CURRENT_ACTIVE_V pinst
                                        WHERE pinst.PAYMENT_PLAN_ID = plan.ID
                                             AND pinst.DUE_DATE >= IN_FROM_DATE
                                             AND pinst.DUE_DATE <= IN_UNTIL_DATE
                                        AND pinst.CODE_TYPE = 'INSTSTATUS'
                                             AND (IN_EXCLUDE_PAID_PAYMENTS = 'N' OR pinst.STATUS_CODE NOT IN ( 'PD', 'SE', 'CP', 'CA', 'WO' )))
                                        AS NUMBER_PLAN_INSTALMENTS,
          ( SELECT TO_CHAR(
                                             ROUND(NVL(SUM(pinst.BROKER_FEE),0),2)      , '9999990.90')
                                        FROM PLAN_INSTAL_CURRENT_ACTIVE_V pinst
                                        WHERE pinst.PAYMENT_PLAN_ID = plan.ID
                                             AND pinst.DUE_DATE >= IN_FROM_DATE
                                             AND pinst.DUE_DATE <= IN_UNTIL_DATE
                                        AND pinst.CODE_TYPE = 'INSTSTATUS'
                                             AND pinst.STATUS_CODE NOT IN ( 'PD', 'SE', 'CP', 'CA', 'WO' )
                                                            ) AS TOTAL_UNPAID_BROKER_FEE
                                        ), --XMLForest
XMLElement ( "INSTALMENTS",
/*==============================================================================
** Get the installments for this payment plan. Select those between the
** the dates specified and excluding paid payments if required. Also, select
** the correct REF_CODE so the description of the status of the payment can be
** added to the output
**=============================================================================*/
( SELECT XMLAGG ( XMLElement ( "INSTALMENT_ROW",
XMLAttributes(LTRIM(TO_CHAR(pinst.DUE_DATE,'ddth fmMonth YYYY'), '0') AS DUE_DATE,
     TRIM(TO_CHAR(ROUND( (pinst.GROSS + pinst.BROKER_FEE) , 2), '9999990.90')) AS AMOUNT,
                                                                                          TRIM(TO_CHAR(ROUND( (pinst.BROKER_FEE) , 2), '9999990.90')) AS BROKER_FEE,
pinst.DESCR AS STATUS,
                                                                                                    pinst.STATUS_CODE AS STATUS_CODE,
                                                                                                    LTRIM(TO_CHAR(pinst.ACTUAL_DATE,'ddth fmMonth YYYY'), '0') AS SINGLE_POLICY_COLLECTION_DATE
) -- End XMLElement
) -- END XMLAGG
                                             FROM PLAN_INSTAL_CURRENT_ACTIVE_V pinst
                                        WHERE pinst.PAYMENT_PLAN_ID = plan.ID
                                             AND pinst.DUE_DATE >= IN_FROM_DATE
                                             AND pinst.DUE_DATE <= IN_UNTIL_DATE
                                        AND pinst.CODE_TYPE = 'INSTSTATUS'
                                             AND (IN_EXCLUDE_PAID_PAYMENTS = 'N' OR pinst.STATUS_CODE NOT IN ( 'PD', 'SE', 'CP', 'CA', 'WO' ))
) -- End SELECT
) -- End XMLElement
) -- End XMLElement
INTO XML_RETURN_BLOCK
FROM PAYMENT_PLAN plan
WHERE plan.ID = IN_PAYMENT_PLAN_ID;
RETURN XML_RETURN_BLOCK;
END;
when more than 4 installment_rows are retrieved; the XML gets corrupted with a weird character appearing in the middle of the 5th row - although the code continues and brings back the results from the LTR_SUB_POLICY_INFO_SP

Similar Messages

  • XMLAGG - Problem using Order By (version 10.1.0.2.0)

    Hi.
    Below is a function I am having a problem compiling when I include the order by parameter on the XMLAGG. If I remove the order by, it compiles fine. I can run the Select statement in SQL Plus (without it being a part of the function) and it works fine. However, as a part of a function it will not work. I am using Oracle 10g 10.1.0.2.0.
    Any Ideas?
    CREATE OR REPLACE
    FUNCTION XML_LEVELPRODUCTS(FULLORDERNO_IN VARCHAR2 DEFAULT NULL)
    RETURN XMLPKG.xml_type
    AS
    XML xmlpkg.xml_type;
    BEGIN
    OPEN XML FOR
    SELECT
    XMLELEMENT("ORDERLINE",
    XMLELEMENT("ORDERNO",S.ORDERNO),
    XMLELEMENT("PRODUCT_TOTAL",F.PRODUCTDOLLARS),
    XMLELEMENT("POSTAGE",F.POSTAGE_HANDLING),
    XMLELEMENT("SALES_TAX",F.SALES_TAX),
    XMLELEMENT("TOTAL",F.ORDER_TOTAL),
    XMLELEMENT("SHIP_METHOD",(select RTRIM(DESCSHORT) from SHIPMETHODS where CODIVSM = COMPANY || DIVISION || SHIPMETHOD AND ROWNUM < 2)),
    XMLELEMENT("SHIP_DATE",TO_CHAR(TO_DATE(SHIPDATE,'YYYYMMDD'), 'MONTH DD, YYYY')),
    (SELECT
    XMLELEMENT("SHIP_ADDRESS",
    XMLELEMENT("CUSTOMER_ID",CUSTOMER.CUSTEDP),
    XMLELEMENT("CUST_NUM",CUSTNO),
    XMLELEMENT("COMPANY_NAME",RTRIM(NAMEX)),
    XMLELEMENT("LAST",RTRIM(LNAME)),
    XMLELEMENT("MI",RTRIM(MI)),
    XMLELEMENT("FIRST",RTRIM(FNAME)),
    XMLELEMENT("FULL_NAME",buildFullName(FNAME,MI,LNAME)),
    XMLELEMENT("PREFIX",CASE SUBSTR(M.CTLDATA,1,1)
    WHEN 'P' THEN RTRIM(SUBSTR(M.CTLDATA,9,40))
    ELSE ''
    END),
    XMLELEMENT("SUFFIX",CASE SUBSTR(M.CTLDATA,1,1)
    WHEN 'S' THEN RTRIM(SUBSTR(M.CTLDATA,9,40))
    ELSE ''
    END),
    XMLELEMENT("STREET",RTRIM(STREET)),
    XMLELEMENT("REF1",RTRIM(REF1)),
    XMLELEMENT("REF2",RTRIM(REF2)),
    XMLELEMENT("CITY",RTRIM(CITY)),
    XMLELEMENT("STATE",RTRIM(STATE)),
    XMLELEMENT("ZIP",RTRIM(ZIP)),
    XMLELEMENT("COUNTRY",(select RTRIM(COUNTRYNAME) from COUNTRIES WHERE COUNTRY= COUNTRYCODE)),
    XMLELEMENT("DAYPHONE",RTRIM(formatPhone(DAYPHONE))),
    XMLELEMENT("NIGHTPHONE",RTRIM(formatPhone(NIGHTPHONE))),
    XMLELEMENT("FAX",RTRIM(formatPhone(FAXPHONE)))
    FROM CUSTOMERS CUSTOMER
    LEFT outer join CUSTOMERPHONE p on p.CUSTEDP = CUSTOMER.CUSTEDP
    LEFT OUTER JOIN CUSTOMERADDL A on A.CUSTEDP = CUSTOMER.CUSTEDP
    LEFT OUTER JOIN CTLMAST M ON M.CTLID = '0000TITLE' || CUSTOMER.TITLE
    WHERE S.SHIPCUSTNO = CUSTOMER.CUSTEDP
    (SELECT XMLAGG(
    XMLELEMENT("PRODUCT",
    XMLELEMENT("SLOTID",SLOTID),
    XMLELEMENT("FULLORDERNO",FULLORDERNO),
    XMLELEMENT("EDPNO",EDPNO),
    XMLELEMENT("ITEMNO",ITEMNO),
    XMLELEMENT("DESCRIPTION",DESCRIPTION),
    XMLELEMENT("LINENUM",LINENUM),
    XMLELEMENT("QTY",QTY),
    XMLELEMENT("PRICE",PRICE),
    XMLELEMENT("PRODUCT_TYPE",PRODUCT_TYPE),
    XMLELEMENT("STATUS",STATUS),
    XMLELEMENT("SHIP_METHOD",(select DESCLONG from SHIPMETHODS where CODIVSM = COMPANY || DIVISION || SHIPMETHOD AND ROWNUM < 2)),
    XMLELEMENT("SHIP_DATE",SHIPDATE),
    (SELECT
    XMLAGG(XMLELEMENT("SERIALNUMS",
    XMLELEMENT("SERIALNUM", SUBSTR(AC.ACTIONCD,1,30))
    FROM ORDERACTIONS AC
    WHERE AC.MESSAGECD = 'SER-NO' AND
    AC.FULLORDERNO = P.FULLORDERNO
    ) ORDER BY P.LINENUM
    FROM CM_ORDER_PRODUCTS P
    where P.FULLORDERNO = S.FULLORDERNO
    FROM CM_ORDER_LEVELS S
    LEFT OUTER JOIN CM_SHIP_FINANCIALS F on S.FULLORDERNO = F.FULLORDERNO
    where S.FULLORDERNO = FULLORDERNO_IN;
    RETURN XML;
    END;
    The compile error is 'PLS-00306: wrong number or types of arguments in call to 'XMLAGG'.

    Here an answer from askTom:
    Hi Tom,
    I am not sure if I can ask this question in this thread or whether you are aware
    of the following problem (as you are very fond of SQL*plus... ;) ).
    I was happily usig toad 7.6 to work with oracle 9i. But now an upgrade to 10g
    has caused toad fail to connect. Error "OCI version 10.1.0.2.0 is not
    supported". But if I install 9i client and try to connect, then it works fine.
    Is there any workaround?
    Thanks and regards
    Praveen
    Followup:
    you'd have to ask the makers of toad if they have a 10g client version or not.
    Basically what is happening is that you have a 9i compiled piece of client
    software (toad).
    it uses, it depends on the 9i client software.
    in order to use the 10g client software -- you'd need a new binary from the
    makers of toad.
    SQLPlus would be the same -- the 9i sqlplus needs the 9i client, the 10g sqlplus
    needs the 10g client and so on.
    As it is -- you are OK right now, you have installed the software needed by toad
    and a 9i client connecting to a 10g database is "ok, supported and normal"

  • Sqlx xmlagg problems

    i am trying to generate xml with sqlx but am having much trouble with the following query:
    SELECT XMLELEMENT("UnitProgramData",
                   XMLAGG(XMLFOREST(UNIT_PROGRAM.UP_ID AS "UnitProgramIDKey"),
                        (SELECT XMLELEMENT("UnitProgramExemptionData", XMLAGG(XMLFOREST(UNIT_PROGRAM_EXEMPTION.UPE_ID AS "UnitProgramExemptionIDKey")))
    FROM UNIT_PROGRAM_EXEMPTION
    WHERE UNIT_PROGRAM.UP_ID = UNIT_PROGRAM_EXEMPTION.UP_ID),
                        (SELECT XMLELEMENT("UnitProgramRepFreqData", XMLAGG(XMLFOREST(UNIT_PROGRAM_REPORTING_FREQ.UPRF_ID AS "UnitProgramRepFrequencyIDKey")))
    FROM UNIT_PROGRAM_REPORTING_FREQ
    WHERE UNIT_PROGRAM.UP_ID = UNIT_PROGRAM_REPORTING_FREQ.UP_ID)
    FROM UNIT_PROGRAM;
    i keep getting:
    ORA-06553: PLS-306: wrong number or types of arguments in call to 'SYS_IXMLAGG'
    when i take the xmlagg out i get multiple rows of type xmltype. it's my understanding that xmlagg should stack these on top of each other. any ideas on what i'm missing?
    thanks
    chris

    Chris, Group By should not be required here as you are already filtering the inner query with the ID from the outer table.
    most likely it should be
    SELECT XMLELEMENT("UnitProgramDatas",
    XMLAGG(xmlelement("UnitProgramData", XMLFOREST(UNIT_PROGRAM.UP_ID AS "UnitProgramIDKey"),xmlagg is to group the fragments together.
    xmlforest is to create set of element together instead of using xmlelement multiple times and also it is usefule incase the column returns NULL values.
    so the sequence should be
    xmlagg(xmlelement("element name", xmlforest))
    try this out.

  • XMLAGG performance problems

    Hello,
    I've been having performance problems with one query using XMLAGG. Explain plan shows that all tables are joined using correct indexes - there is nothing wrong with it. After series of experiments with the query I found out that the problem is in use of XMLAGG function. It aggregates the data before submitting it to the result XML document.
    I there any way to generate something like
    <Main attr1="...">
    <el1>...</el1>
    <el2>...</el2>
    <SubElement>
    <row>row1 from the database</row>
    <row>row2 from the database</row>
    <row>rowN from the database</row>
    </SubElement>
    <Main>
    without using XMLAGG in the subquery or somehow switch the aggregation off? I dont really need the records to be aggregated, all I need is to be able to generate multiple record based XML in the subquery which would have normally failed on (single-row query returned more than one record exception) without XMLAGG.
    Thanks in advance
    Alexey

    TKPROF: Release 9.2.0.1.0 - Production on Wed Jan 31 15:21:34 2007
    Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
    Trace file: lnsqd1_ora_7350_perfoamance_test_01.trc
    Sort options: default
    count = number of times OCI procedure was executed
    cpu = cpu time in seconds executing
    elapsed = elapsed time in seconds executing
    disk = number of physical reads of buffers from disk
    query = number of buffers gotten for consistent read
    current = number of buffers gotten in current mode (usually for update)
    rows = number of rows processed by the fetch or execute call
    ALTER SESSION SET EVENTS '10046 trace name context forever, level 1'
    call count cpu elapsed disk query current rows
    Parse 0 0.00 0.00 0 0 0 0
    Execute 1 0.00 0.00 0 0 0 0
    Fetch 0 0.00 0.00 0 0 0 0
    total 1 0.00 0.00 0 0 0 0
    Misses in library cache during parse: 0
    Optimizer goal: ALL_ROWS
    Parsing user id: 113
    create table tmp_003
    as
    select a.*, 'NEW ' as eventtype
    from v_deal_xml a
    where a.deal_id in
    select a.pk_value
    from da_history a, gx_type b
    where a.evtime <= to_date('1/22/2007 12:59:26', 'MM/DD/RRRR HH24:MI:SS')
    and a.type_id = b.type_id
    and b.xmltype = 'GDP/DEAL'
    and a.eventtype = 'NEW'
    call count cpu elapsed disk query current rows
    Parse 1 0.12 0.12 0 60 1 0
    Execute 1 108.30 105.87 0 6343 1387 172
    Fetch 0 0.00 0.00 0 0 0 0
    total 2 108.42 106.00 0 6403 1388 172
    Misses in library cache during parse: 1
    Optimizer goal: ALL_ROWS
    Parsing user id: 113
    insert into tmp_003
    select a.*, 'UPDATE' as eventtype
    from v_deal_xml a
    where a.deal_id in
    select a.pk_value --b.xmltype, a.*
    from da_history a, gx_type b
    where a.evtime <= to_date('1/22/2007 12:59:26', 'MM/DD/RRRR HH24:MI:SS')
    and a.type_id = b.type_id
    and b.xmltype = 'GDP/DEAL'
    and a.eventtype = 'UPDATE'
    call count cpu elapsed disk query current rows
    Parse 1 0.13 0.13 0 60 0 0
    Execute 1 256.74 250.96 0 18752 3815 381
    Fetch 0 0.00 0.00 0 0 0 0
    total 2 256.87 251.09 0 18812 3815 381
    Misses in library cache during parse: 1
    Optimizer goal: ALL_ROWS
    Parsing user id: 113
    Rows Row Source Operation
    381 NESTED LOOPS (cr=1194 pr=0 pw=0 time=26458 us)
    381 VIEW VW_NSO_1 (cr=430 pr=0 pw=0 time=6665 us)
    381 SORT UNIQUE (cr=430 pr=0 pw=0 time=6285 us)
    381 MERGE JOIN (cr=430 pr=0 pw=0 time=3761 us)
    1 TABLE ACCESS BY INDEX ROWID GX_TYPE (cr=2 pr=0 pw=0 time=67 us)
    5 INDEX FULL SCAN XPKGX_TYPE (cr=1 pr=0 pw=0 time=24 us)(object id 71282)
    381 SORT JOIN (cr=428 pr=0 pw=0 time=3698 us)
    603 TABLE ACCESS FULL DA_HISTORY (cr=428 pr=0 pw=0 time=1339 us)
    381 TABLE ACCESS BY INDEX ROWID DEAL (cr=764 pr=0 pw=0 time=16692 us)
    381 INDEX UNIQUE SCAN DEAL_PK (cr=383 pr=0 pw=0 time=8926 us)(object id 71236)
    commit
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 1 0.00 0.00 0 0 1 0
    Fetch 0 0.00 0.00 0 0 0 0
    total 2 0.00 0.00 0 0 1 0
    Misses in library cache during parse: 0
    Parsing user id: 113
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call count cpu elapsed disk query current rows
    Parse 3 0.25 0.25 0 120 1 0
    Execute 4 365.04 356.84 0 25095 5203 553
    Fetch 0 0.00 0.00 0 0 0 0
    total 7 365.29 357.10 0 25215 5204 553
    Misses in library cache during parse: 2
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call count cpu elapsed disk query current rows
    Parse 83 0.01 0.01 0 0 0 0
    Execute 125 0.03 0.03 0 108 201 46
    Fetch 114 0.01 0.00 0 221 0 72
    total 322 0.05 0.04 0 329 201 118
    Misses in library cache during parse: 3
    Misses in library cache during execute: 3
    4 user SQL statements in session.
    125 internal SQL statements in session.
    129 SQL statements in session.
    Trace file: lnsqd1_ora_7350_perfoamance_test_01.trc
    Trace file compatibility: 9.00.01
    Sort options: default
    1 session in tracefile.
    4 user SQL statements in trace file.
    125 internal SQL statements in trace file.
    129 SQL statements in trace file.
    45 unique SQL statements in trace file.
    11196 lines in trace file.

  • XmlAgg first n ordered elements only problem

    I cannot find a way on Oracle to limit the number of rows aggregated by XmlAgg to only the first n in a specified order. I have produced a simple example demonstrating my problem which should be easy to replicate, as follows:
    I have two tables, INCIDENT and INCIDENT_LOG_ENTRY (there may be many entries for a given incident).
    I wish to extract details (as XML) of an incident and its most recent two log entries only.
    -- Create INCIDENT table and two incidents:
    create table INCIDENT (ID NUMBER(10,0) PRIMARY KEY, INCIDENT_SUMMARY VARCHAR2(200));
    insert into INCIDENT values (1, 'Hold up');
    insert into INCIDENT values (2, 'Car Crash');
    -- Create INCIDENT_LOG_ENTRY table and log entries for both incidents:
    CREATE table INCIDENT_LOG_ENTRY (ID NUMBER(10,0) PRIMARY KEY, INCIDENT_ID NUMBER(10,0), ENTRY_DATE_TIME DATE, ENTRY_TEXT VARCHAR2(500));
    insert into INCIDENT_LOG_ENTRY values (1, 1, TO_DATE('2009-01-01 08:15:11', 'YYYY-MM-DD HH24:MI:SS'), 'Hold up on Main Street');
    insert into INCIDENT_LOG_ENTRY values (2, 1, TO_DATE('2009-01-01 08:17:40', 'YYYY-MM-DD HH24:MI:SS'), 'Suspect pursued in high speed chase');
    insert into INCIDENT_LOG_ENTRY values (3, 1, TO_DATE('2009-01-01 08:20:29', 'YYYY-MM-DD HH24:MI:SS'), 'Suspect lost in traffic');
    insert into INCIDENT_LOG_ENTRY values (4, 1, TO_DATE('2009-01-03 11:55:31', 'YYYY-MM-DD HH24:MI:SS'), 'Suspect apprehended in hospital');
    insert into INCIDENT_LOG_ENTRY values (21, 2, TO_DATE('2009-01-01 08:29:15', 'YYYY-MM-DD HH24:MI:SS'), 'Collision between car jumping red light and lorry');
    insert into INCIDENT_LOG_ENTRY values (22, 2, TO_DATE('2009-01-01 08:45:53', 'YYYY-MM-DD HH24:MI:SS'), 'Driver taken to hospital');
    Here is the query (note order by is within xmlAgg as per Oracle documentation):
    SELECT xmlAgg(xmlElement("INCIDENT", xmlForest(i.ID, i.INCIDENT_SUMMARY),
    xmlElement("INCIDENT_LOG_ENTRIES",
    (SELECT xmlAgg(xmlElement("INCIDENT_LOG_ENTRY", xmlForest(ile.ID, ile.ENTRY_DATE_TIME, ile.ENTRY_TEXT)) order by ile.ENTRY_DATE_TIME desc)
    FROM INCIDENT_LOG_ENTRY ile
    WHERE ile.INCIDENT_ID = i.ID
    AND rownum <= 2
    FROM INCIDENT i where i.ID = 1
    And here is its output:
    <INCIDENT>
    <ID>1</ID>
    <INCIDENT_SUMMARY>Hold up</INCIDENT_SUMMARY>
    <INCIDENT_LOG_ENTRIES>
    <INCIDENT_LOG_ENTRY>
    <ID>2</ID>
    <ENTRY_DATE_TIME>01-JAN-09</ENTRY_DATE_TIME>
    <ENTRY_TEXT>Suspect pursued in high speed chase</ENTRY_TEXT>
    </INCIDENT_LOG_ENTRY>
    <INCIDENT_LOG_ENTRY>
    <ID>1</ID>
    <ENTRY_DATE_TIME>01-JAN-09</ENTRY_DATE_TIME>
    <ENTRY_TEXT>Hold up on Main Street</ENTRY_TEXT>
    </INCIDENT_LOG_ENTRY>
    </INCIDENT_LOG_ENTRIES>
    </INCIDENT>
    This is not the desired result - I want the two most recent log entries (4 and 3). Clearly the rownum has taken effect before the ordering is applied by XmlAgg. However, if I try to force the ordering first by using a nested subquery, Oracle complains that the incident (table alias 'i') is not visible within the subquery:
    SELECT xmlAgg(xmlElement("INCIDENT", xmlForest(i.ID, i.INCIDENT_SUMMARY),
    xmlElement("INCIDENT_LOG_ENTRIES",
    (SELECT xmlAgg(xmlElement("INCIDENT_LOG_ENTRY", xmlForest(ile.ID, ile.ENTRY_DATE_TIME, ile.ENTRY_TEXT)) order by ile.ENTRY_DATE_TIME desc)
    FROM (select * from (select * from INCIDENT_LOG_ENTRY WHERE INCIDENT_ID = i.ID order by ENTRY_DATE_TIME) where rownum <= 2) ile
    FROM INCIDENT i where i.ID = 1
    Which results in:
    SQL Error: ORA-00904: "I"."ID": invalid identifier
    If anyone knows how to resolve this problem I would be extremely grateful.
    (BTW, it works without any trouble on SQL Server:
    select i.ID, i.INCIDENT_SUMMARY,
    (select top 2 ile.ID, ile.ENTRY_TEXT, ile.ENTRY_DATE_TIME
    from INCIDENT_LOG_ENTRY ile
    where ile.INCIDENT_ID = i.ID
    order by ile.ENTRY_DATE_TIME desc for xml path('INCIDENT_LOG_ENTRY'), type) as "INCIDENT_LOG_ENTRIES"
    from INCIDENT i
    where i.ID = 1
    for xml path('INCIDENT'), type
    Which yields the desired result:
    <INCIDENT>
    <ID>1</ID>
    <INCIDENT_SUMMARY>Hold up</INCIDENT_SUMMARY>
    <INCIDENT_LOG_ENTRIES>
    <INCIDENT_LOG_ENTRY>
    <ID>4</ID>
    <ENTRY_TEXT>Suspect apprehended in hospital</ENTRY_TEXT>
    <ENTRY_DATE_TIME>2009-01-03T11:55:31</ENTRY_DATE_TIME>
    </INCIDENT_LOG_ENTRY>
    <INCIDENT_LOG_ENTRY>
    <ID>3</ID>
    <ENTRY_TEXT>Suspect lost in traffic</ENTRY_TEXT>
    <ENTRY_DATE_TIME>2009-01-01T08:20:29</ENTRY_DATE_TIME>
    </INCIDENT_LOG_ENTRY>
    </INCIDENT_LOG_ENTRIES>
    </INCIDENT>
    )

    Hi,
    Sorry, I don't know how to get the first 2 rows in the XML functions, which, no doubt, is the best way to do it.
    At the table level, you can assign numbers to every log entry in a sub-query, and use that number (instead of ROWNUM) to get the top 2:
    WITH   numbered_log_entry
    AS
         SELECT     id, incident_id, entry_date_time, entry_text
         ,     RANK () OVER ( PARTITION BY  incident_id
                               ORDER BY          entry_date_time     DESC
                        ) AS rnk
         FROM     incident_log_entry
    SELECT  xmlAgg ( xmlElement ( "INCIDENT"
                               , xmlForest (i.ID, i.INCIDENT_SUMMARY)
                       , xmlElement ( "INCIDENT_LOG_ENTRIES"
                                    , ( SELECT  xmlAgg ( xmlElement ( "INCIDENT_LOG_ENTRY"
                                                                  , xmlForest ( ile.ID
                                                              , ile.ENTRY_DATE_TIME
                                                           , ile.ENTRY_TEXT
                                                  ) order by ile.ENTRY_DATE_TIME desc
                                  FROM    numbered_LOG_ENTRY ile     -- Changed
                                  WHERE   ile.INCIDENT_ID      = i.ID
                                  AND     rnk          <= 2     -- Changed
    FROM    INCIDENT   i
    where      i.ID        = 1;Notice that the main query is exatcly what you posted, except for the 2 line marked "Changed".
    Thanks for posting the CREATE TABLE and INSERT statments! That made it really easy to test.
    You may have noticed that this site compresses whitespace.
    When you have to post formated code or output on this site, type these 6 characters:
    &#123;code&#125;
    (small letters only, inside curly brackets) before and after sections of formatted text, to preserve spacing.

  • Script for generating XML file ... problem with null values

    Greetings everyone,
    i come here with a question that troubles me for some time now. I have a script which i run from SQLPLUS every now and then to generate an XML file.
    Problem is that data which needs to be in XML is not allways <> NULL and i need to hide those tags that are empty </tag>.
    I will post below my script and if you could help me with it it would be really great!
    Thanks for reading!
    set long 20000000
    set long 20000000
    set linesize 32000
    SET ECHO OFF
    SET TRIMSPOOL on
    SET HEADING OFF
    SET PAGESIZE 50000
    SET VERIFY OFF
    SET FEEDBACK OFF
    SET TERMOUT OFF
    spool C:\test.xml
    set serveroutput on
    begin
      dbms_output.put_line('<?xml version="1.0" encoding="utf-8" ?>');
    end;
    SELECT
    XMLELEMENT("ReportRoot",XMLATTRIBUTES('http://www.w3.org/2001/XMLSchema-instance' as "xmlns:xsi", 'http://www.w3.org/2001/XMLSchema' as "xmlns:xsd" , '1.0' as "Version",sysdate as "CreationDate",to_char(sysdate,'hh:mm:ss') as "CreationTime",'1524544845' as "id"),
    XMLELEMENT("Porocila",XMLELEMENT("JOLY",(SELECT XMLAGG (XMLELEMENT("RefNrReport",replace('SON'||to_char(ref_ST,'00000'),' ',''))) from access_table_2 where ref_ST = &1),
    XMLELEMENT("ReportDate",sysdate),XMLELEMENT("Labeling",'545254450'),
    (SELECT XMLAGG     (XMLELEMENT("Reportf",
                                                                     XMLELEMENT("access",access),
                                                                     XMLELEMENT("date",date),
                                                                     XMLELEMENT("datep",datep),
                                                                     XMLELEMENT("ModificationInfo",'M'),XMLELEMENT("ModificationReason",modireason)))
                                                 from v_xml_test where id_dok = &1 and ind_print = '1'))))
      .extract('/*')
      from dual
         spool off
    exitNow lets pretend that XMLELEMENT("datep",datep), is sometimes NULL and i do not want to display it.

    may be
    with t as
    select sysdate datep from dual union all
    select null datep from dual
    select xmlagg(xmlelement("Reportf",
                             case when datep is not null then XMLELEMENT("datep", datep)
                             end
      from t

  • Problem with XML in APEX ORA-06502

    i, I have a problem with XML generation, I developed an application in APEX, and in a html page I have this process:
    declare
    l_XML varchar2(32767);
    begin
    select xmlElement
    "iva",
    xmlElement("numeroRuc",J.RUC),
    xmlElement("razonSocial", J.RAZON_SOCIAL),
    xmlElement("idRepre", J.ID_REPRE),
    xmlElement("rucContador", J.RUC_CONTADOR),
    xmlElement("anio", J.ANIO),
    xmlElement("mes", J.MES),
    xmlElement
    "compras",
    select xmlAgg
    xmlElement
    "detalleCompra",
    --xmlAttributes(K.ID_COMPRA as "COMPRA"),
    xmlForest
    K.COD_SUSTENTO as "codSustento",
    K.TPLD_PROV as "tpldProv",
    K.ID_PROV as "idProv",
    K.TIPO_COMPROBANTE as "tipoComprobante",
    to_char(K.FECHA_REGISTRO, 'DD/MM/YYYY') as "fechaRegistro",
    K.ESTABLECIMIENTO as "establecimiento",
    K.PUNTO_EMISION as "puntoEmision",
    K.SECUENCIAL as "secuencial",
    to_char(K.FECHA_EMISION, 'DD/MM/YYYY') as "fechaEmision",
    K.AUTORIZACION as "autorizacion",
    to_char(K.BASE_NO_GRA_IVA, 9999999999.99) as "baseNoGraIva",
    to_char(K.BASE_IMPONIBLE, 9999999999.99) as "baseImponible",
    to_char(K.BASE_IMP_GRAV, 9999999999.99) as "baseImpGrav",
    to_char(K.MONTO_ICE, 9999999999.99) as "montoIce",
    to_char(K.MONTO_IVA, 9999999999.99) as "montoIva",
    to_char(K.VALOR_RET_BIENES, 9999999999.99) as "valorRetBienes",
    to_char(K.VALOR_RET_SERVICIOS, 9999999999.99) as "valorRetServicios",
    to_char(K.VALOR_RET_SERV_100, 9999999999.99) as "valorRetServ100"
    xmlElement
    "air",
    select xmlAgg
    xmlElement
    "detalleAir",
    xmlForest
    P.COD_RET_AIR as "codRetAir",
    to_char(P.BASE_IMP_AIR, 9999999999.99) as "baseImpAir",
    to_char(P.PORCENTAJE_AIR, 999.99) as "porcentajeAir",
    to_char(P.VAL_RET_AIR, 9999999999.99) as "valRetAir"
    from ANEXO_COMPRAS P
    where P.ID_COMPRA = K.ID_COMPRA
    AND P.ID_INFORMANTE_XML = K.ID_INFORMANTE_XML
    xmlElement("estabRetencion1", K.ESTAB_RETENCION_1),
    xmlElement("ptoEmiRetencion1", K.PTO_EMI_RETENCION_1),
    xmlElement("secRetencion1", K.SEC_RETENCION_1),
    xmlElement("autRetencion1", K.AUT_RETENCION_1),
    xmlElement("fechaEmiRet1", to_char(K.FECHA_EMI_RET_1,'DD/MM/YYYY')),
    xmlElement("docModificado", K.DOC_MODIFICADO),
    xmlElement("estabModificado", K.ESTAB_MODIFICADO),
    xmlElement("ptoEmiModificado", K.PTO_EMI_MODIFICADO),
    xmlElement("secModificado", K.SEC_MODIFICADO),
    xmlElement("autModificado", K.AUT_MODIFICADO)
    from SRI_COMPRAS K
    WHERE K.ID IS NOT NULL
    AND K.ID_INFORMANTE_XML = J.ID_INFORMANTE
    AND K.ID BETWEEN 1 AND 25
    ).getClobVal()
    into l_XML
    from ANEXO_INFORMANTE J
    where J.ID_INFORMANTE =:P3_MES
    and J.RUC =:P3_ID_RUC
    and J.ANIO =:P3_ANIO
    and J.MES =:P3_MES;
    --HTML
    sys.owa_util.mime_header('text/xml',FALSE);
    sys.htp.p('Content-Length: ' || length(l_XML));
    sys.owa_util.http_header_close;
    sys.htp.print(l_XML);
    end;
    Now my table has more than 900 rows and only when I specifically selected 25 rows of the table "ANEXO_COMPRAS" in the where ( AND K.ID BETWEEN 1 AND 25) the XML is generated.+
    I think that the problem may be the data type declared "varchar2", but I was trying with the data type "CLOB" and the error is the same.+
    declare
    l_XML CLOB;
    begin
    --Oculta XML
    sys.htp.init;
    wwv_flow.g_page_text_generated := true;
    wwv_flow.g_unrecoverable_error := true;
    --select XML
    select xmlElement
    from SRI_COMPRAS K
    WHERE K.ID IS NOT NULL
    AND K.ID_INFORMANTE_XML = J.ID_INFORMANTE
    ).getClobVal()
    into l_XML
    from ANEXO_INFORMANTE J
    where J.ID_INFORMANTE =:P3_MES
    and J.RUC =:P3_ID_RUC
    and J.ANIO =:P3_ANIO
    and J.MES =:P3_MES;
    --HTML
    sys.owa_util.mime_header('text/xml',FALSE);
    sys.htp.p('Content-Length: ' || length(l_XML));
    sys.owa_util.http_header_close;
    sys.htp.print(l_XML);
    end;
    The error generated is ORA-06502: PL/SQL: numeric or value error+_
    Please I need your help. I don`t know how to resolve this problem, how to use the data type "CLOB" for the XML can be generate+

    JohannaCevallos07 wrote:
    Now my table has more than 900 rows and only when I specifically selected 25 rows of the table "ANEXO_COMPRAS" in the where ( AND K.ID BETWEEN 1 AND 25) the XML is generated.+
    I think that the problem may be the data type declared "varchar2", but I was trying with the data type "CLOB" and the error is the same.+
    The error generated is ORA-06502: PL/SQL: numeric or value error+_
    Please I need your help. I don`t know how to resolve this problem, how to use the data type "CLOB" for the XML can be generate+The likeliest explanation for this is that length of the XML exceeds 32K, which is the maximum size that <tt>htp.p</tt> can output. A CLOB can store much more than this, so it's necessary to buffer the output as shown in +{message:id=4497571}+
    Help us to help you. When you have a problem include as much relevant information as possible upfront. This should include:
    <li>Full APEX version
    <li>Full DB/version/edition/host OS
    <li>Web server architecture (EPG, OHS or APEX listener/host OS)
    <li>Browser(s) and version(s) used
    <li>Theme
    <li>Template(s)
    <li>Region/item type(s) (making particular distinction as to whether a "report" is a standard report, an interactive report, or in fact an "updateable report" (i.e. a tabular form)
    And always post code wrapped in <tt>\...\</tt> tags, as described in the FAQ.
    Thanks

  • Report Problem need to fix the code

    Hello Expert
    I am new to apex, I was given a task to interpret the code and fix the problem.
    This Apex application has a list of value where the user select the institution as a drop down list menu. After selecting the institution the main report below the drop down list will be populated based on the selection. The problem is that when the user insert record for standalone program, this insert don't appear on the report when the user select the instituion.
    can someone look at the code below and explain to me line by line what it does and how can I twick it to solve this problem? I am cloue less and I need expert help
    select dt.* 
             ,case when dt.delivery_location is null then null
                      else htf.anchor ('javascript:void(0);'
                                              ,'<img src=#APP_IMAGES#location.png
                                                title=''' ||dt.delivery_location || '''
                                                alt=''' ||dt.delivery_location || '''
                                                height=24 width=24/>'
              end dl_hover
      from (
    select
            CASE WHEN INDEP_DEGREE = 'Y' THEN
            CASE WHEN Dt.DEGREE_ACRONYM IN ('AACC','ASCC') then
              da.DESCRIPTION   || ' with an Emphasis Area of ' ||
                     NVL(Mt.DESCRIPTION,cC.DESCRIPTION)
                ELSE    
             nvl(dt.description, da.DESCRIPTION)
             END
             ELSE
                CASE WHEN Dt.DEGREE_LEVEL IN ('V','A') THEN
                     nvl(dt.description, da.DESCRIPTION )  || ' with an Option in ' ||
                     NVL(Mt.DESCRIPTION,Cc.DESCRIPTION)
                WHEN Dt.DEGREE_LEVEL IN ('E','C','Z','F')  THEN
                     nvl(dt.description, da.DESCRIPTION )  || ' in ' ||
                     NVL(Mt.DESCRIPTION,Cc.DESCRIPTION)
                ELSE    
                     nvl(dt.description, da.DESCRIPTION )  || ' with a Major in ' ||
                     NVL(Mt.DESCRIPTION,Cc.DESCRIPTION)
                END
        END
    degree_name
    --,'???' emphasis_area
    ,nvl(mt.cip_code,dt.cip_code) cip_code
    ,nvl(mt.hours, dt.hours) total_credit_hours
    -- ,dt.deactivated status
    ,case when nvl(mt.deactivated,dt.deactivated)  = 'A' then 'Active'
              when nvl(mt.deactivated,dt.deactivated) = 'D' then 'Deactivated'
              when nvl(mt.deactivated,dt.deactivated) = 'T' then 'Terminated'
          WHEN NVL(mt.deactivated,dt.deactivated) = 'I'
          THEN 'Inactive'
              else null
       end status
    --,dt.degree_level program_type
    ,dl.description program_type
    ,dt.coop_indicator coop_indicator
    ,nvl(mt.approval_date,dt.approval_date) approval_date
    ,nvl(mt.implemented,dt.implemented) implemented
    ,nvl(mt.implementation_date, dt.implementation_date) implementation_date
    ,nvl(mt.delivery_mode ,dt.delivery_mode) delivery_mode
    ,(select rtrim(replace(replace(xmlagg(xmlelement("C" ,c.cixxvext_name)).getclobval() ,'<C>' ,'') ,'</C>' ,'&#xD; ') ,'&#xD; ') C
      from degree_transaction_details dtd
             ,cixxvext c
      where (dtd.degree_transaction_id = case when INDEP_DEGREE= 'Y' then dt.degree_id else mt.major_id end )
          and c.cixxvext_ext_site_cd = dtd.detail_value
    and dtd.record_type= case when INDEP_DEGREE = 'Y' then 'DEGREE' else 'MAJOR' end ) delivery_location
    ,dt.degree_id degree_id
    ,'Comparison Report' comparison_report
    ,apex_util.prepare_url ('f?p=&APP_ID.:2:&SESSION.::&DEBUG.:2:P2_FICE_CODE,P2_DEGREE_ID:&P1_FICE_CODE.,'||dt.degree_id) edit_link
    ,apex_util.prepare_url ('f?p=&APP_ID.:4:&SESSION.::&DEBUG.:RP,4:P4_DEGREE_ID:'||dt.degree_id) cr_link
    ,dt.description
    ,mt.major_id major_id
    ,nvl(mt.online_percentage,dt.online_percentage) online_percent
    ,nvl(mt.last_inst_review,dt.last_inst_review) last_inst_review
    from degree_transactions dt,
        degree_acronyms da,
        major_transactions mt,
        degree_levels dl,
        cip_codes cc
    where dt.degree_id = mt.degree_id
      and mt.cip_code = cc.cip_code
      and dl.degree_level = nvl(mt.degree_level,dt.degree_level)
      and dt.degree_acronym = da.degree_acronym
      and dt.Fice_code = da.fice_code
      and dt.degree_level = da.degree_level
      and dt.deactivated in ('A','D')
      and mt.deactivated in ('A','D')
      and dt.fice_code = :P1_FICE_CODE
      and dt.show_inst = 'Y'
    ) dt
    order by dt.description nulls first

    You said:
    "I was able to debug the code in SQL Developer."  Does this mean that you:
    ran the code, got results
    then set indep_degree to 'Y' on a row in your database
    ran the code again and saw the results you are looking for?
    If true, your code is working and should operate the same in APEX.
    So if your code is working, we need to understand what processes are running on the form and when they are firing.
    Jeff

  • ORDER BY Clause in XMLAGG is throwing errors.

    Hi,
    I'm getting errors when generating the XML using the ORDER BY clause in the XMLAgg function. Although, running the SQL directly in SQL Plus doesn't have any problem.
    Here is the PL/SQL sample.
    DECLARE
    vX_XML SYS.XMLTYPE;
    vCL_XML CLOB;
    BEGIN
    SELECT XMLElement("GROUP",
    XMLAttributes(Group_Id AS "ID", Group_Name AS "NAME", Group_Description AS "DESC"),
    XMLAgg(XMLElement("FIELD",
    XMLAttributes(Field_Id AS "ID", Field_Description AS "DESC",
    Table_Name AS "TAB_NM", Rule_Name AS "RULE_NM",
    Field_Hierarchy_Depth AS "DOL_VAR_CALC")) ORDER BY Field_Description))
    INTO vX_XML
    FROM (SELECT g.Group_Id, g.Group_Name, g.Group_Description, f.Field_Id, f.Field_Description,
    DECODE(f.Table_Name, 'ESTIMATES', 'E', 'LINE_ITEMS', 'L', NULL) Table_Name,
    rt.Rule_Name,
    CASE NVL(f.Field_Hierarchy_Depth, 0) WHEN 0 THEN 'N' ELSE 'Y' END Field_Hierarchy_Depth
    FROM GROUPS g,
    Rules r,
    Rule_Types rt,
    Fields f
    WHERE g.Group_Id = 3087
    AND r.Group_Id_Fk = g.Group_Id
    AND rt.Rule_Type_Id = r.Rule_Type_Id_Fk
    AND f.Field_Id = r.Field_Id_Fk) tab
    GROUP BY Group_Id, Group_Name, Group_Description;
    vCL_XML := vX_XML.GetCLOBVal();
    END;
    And, here are the errors.
    ERROR at line 8:
    ORA-06550: line 8, column 23:
    PLS-00306: wrong number or types of arguments in call to 'XMLAGG'
    ORA-06550: line 8, column 23:
    PL/SQL: ORA-00904: "XMLAGG": invalid identifier
    ORA-06550: line 6, column 5:
    PL/SQL: SQL Statement ignored
    Thanks in Advance.
    BTW, we are using Oracle 9.2.0.4.

    This is bug 2785463 with no ETA for a fix
    regards
    Coby D. Adams Jr.

  • Problem using existsnode from view

    I am having a problem using existsnode from a view. I am currently using 10.2.0.3
    example
    CREATE OR REPLACE VIEW XML_PERSON_ASSOCIATION
    (PERSON)
    AS
    select
    xmlelement("Person",
        xmlforest(
            extractvalue(value(p),'/Person/PersonID') "PersonID",
            extractvalue(value(p),'/Person/Prefix') "Prefix",
            extractvalue(value(p),'/Person/FirstName') "FirstName",
            extractvalue(value(p),'/Person/MiddleName') "MiddleName",
            extractvalue(value(p),'/Person/LastName') "LastName",
            extractvalue(value(p),'/Person/Suffix') "Suffix",
            extractvalue(value(p),'/Person/PreferredName') "PreferredName",
            extractvalue(value(p),'/Person/Gender') "Gender",
            extractvalue(value(p),'/Person/PrimaryLanguage') "PrimaryLanguage",
            extractvalue(value(p),'/Person/RecordStatus') "RecordStatus",
            extractvalue(value(p),'/Person/ImportedDate') "ImportedDate",
            (select
                xmlagg(
                    xmlelement("Association",
                        xmlforest(
                            extractvalue(value(oa),'/OrganizationPersonAssoc/Name') "Name",
                            extractvalue(value(ot),'/OrganizationType/OrganizationID') "OrganizationID",
                            extractvalue(value(ot),'/OrganizationType/Type') "OrganizationType",
                            extractvalue(value(a),'/Association/Role') "Role",                        
                            extractvalue(value(a),'/Association/RecordStatus') "RecordStatus",
                            extractvalue(value(oa),'/OrganizationPersonAssoc/ImportedDate') "ImportedDate"                                                
                        xmlelement("PersonTypes",
                            extract(value(per),'/Person/PersonTypes/PersonType')
                        xmlelement("Addresses",
                            extract(value(a),'/Association/Addresses/Address')
                        xmlelement("ContactMechanisms",
                            extract(value(a),'/Association/ContactMechanisms/ContactMechanism')
            from org_person_assoc oa,
            table(xmlsequence(extract(value(oa),'/OrganizationPersonAssoc/OrganizationTypes/OrganizationType'))) ot,
            table(xmlsequence(extract(value(ot),'/OrganizationType/Associations/Association'))) a,
            table(xmlsequence(extract(value(a),'/Association/Persons/Person'))) per
            where extractvalue(value(per),'/Person/PersonID') = extractvalue(value(p),'/Person/PersonID')        
            ) "Associations"
    ) person
    from person p
    /When I run the following statment
    select person
    from xml_person_association o
    where existsnode(person,'/Person/Associations/Association[OrganizationID=30097]')=1;
    I get no records returned. Now if I used the extract function and use the same path that's in the existsnode clause I get a record returned.
    select extract(person,'/Person/Associations/Association')
    from xml_person_association o
    where existsnode(person,'/Person/Associations/Association[OrganizationID=30097]')=1;
    <Association>
    <Name>TEST DATA</Name>
    <OrganizationID>30097</OrganizationID>
    </Association>
    If I run the same style of existsnode statment against a table directly instead of a view I am not required to use an extract caluse that has the same path that is used in the existsnode clause.
    Thanks for the help.
    Message was edited by:
    mdrake

    Testing in 11g I get
    SQL>
    SQL>
    SQL> set echo on
    SQL> spool testcase.log
    SQL> --
    SQL> connect sys/ as sysdba
    Enter password:
    Connected.
    SQL> set define on
    SQL> set timing on
    SQL> --
    SQL> define USERNAME = XDBTEST
    SQL> --
    SQL> def PASSWORD = XDBTEST
    SQL> --
    SQL> def USER_TABLESPACE = USERS
    SQL> --
    SQL> def TEMP_TABLESPACE = TEMP
    SQL> --
    SQL> drop user &USERNAME cascade
      2  /
    old   1: drop user &USERNAME cascade
    new   1: drop user XDBTEST cascade
    User dropped.
    Elapsed: 00:00:09.42
    SQL> grant connect, resource to &USERNAME identified by &PASSWORD
      2  /
    old   1: grant connect, resource to &USERNAME identified by &PASSWORD
    new   1: grant connect, resource to XDBTEST identified by XDBTEST
    Grant succeeded.
    Elapsed: 00:00:00.03
    SQL> grant create any directory, drop any directory to &USERNAME
      2  /
    old   1: grant create any directory, drop any directory to &USERNAME
    new   1: grant create any directory, drop any directory to XDBTEST
    Grant succeeded.
    Elapsed: 00:00:00.00
    SQL> grant alter session, create view to &USERNAME
      2  /
    old   1: grant alter session, create view to &USERNAME
    new   1: grant alter session, create view to XDBTEST
    Grant succeeded.
    Elapsed: 00:00:00.00
    SQL> alter user &USERNAME default tablespace &USER_TABLESPACE temporary tablespace &TEMP_TABLESPACE
      2  /
    old   1: alter user &USERNAME default tablespace &USER_TABLESPACE temporary tablespace &TEMP_TABLESPACE
    new   1: alter user XDBTEST default tablespace USERS temporary tablespace TEMP
    User altered.
    Elapsed: 00:00:00.00
    SQL> connect &USERNAME/&PASSWORD
    Connected.
    SQL> --
    SQL> alter session set events ='19027 trace name context forever, level 0x800'
      2  /
    Session altered.
    Elapsed: 00:00:00.00
    SQL> var xmlText1 clob
    SQL> var xmlText2 clob
    SQL> var xmlSchema clob
    SQL> var schemaURL varchar2(256)
    SQL> --
    SQL> begin
      2    :schemaURL := 'mcs.xsd';
      3    :xmlSchema :=
      4  '<!-- edited with XMLSpy v2007 sp2 (http://www.altova.com) by Shaun (PPD Inc) --> <s:schema xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:xdb=
    "http://xmlns.oracle.com/xdb" elementFormDefault="qualified" xdb:storeVarrayAsTable="true">
      5     <s:element name="Organization" type="Organization" xdb:defaultTable="ORG"/>
      6     <s:element name="Person" type="Person" xdb:defaultTable="PERSON"/>
      7     <s:element name="OrganizationPersonAssoc" type="Organization" xdb:defaultTable="ORG_PERSON_ASSOC"/>
      8     <s:complexType name="Organization" xdb:SQLType="Organization">
      9             <s:sequence minOccurs="0">
    10                     <s:element name="Name" type="s:string" nillable="true"/>
    11                     <s:element name="LongName" type="s:string" nillable="true"/>
    12                     <s:element name="Description" type="s:string" nillable="true"/>
    13                     <s:element name="FWANumber" type="s:string" nillable="true"/>
    14                     <s:element name="GUID" type="s:string" nillable="true"/>
    15                     <s:element name="CreatedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    16                     <s:element name="LastModifiedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    17                     <s:element name="RecordStatus" type="s:string" nillable="true"/>
    18                     <s:element name="RecordStatusDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    19                     <s:element name="OrganizationTypes" type="ArrayOfOrganizationType" minOccurs="0"/>
    20                     <s:element name="OrganizationSynonyms" type="ArrayOfOrganizationSynonym"/>
    21                     <s:element name="ImportedDate" type="s:date"/>
    22             </s:sequence>
    23     </s:complexType>
    24     <s:complexType name="ArrayOfOrganizationType" xdb:SQLType="ArrayOfOrganizationType">
    25             <s:sequence minOccurs="0">
    26                     <s:element name="OrganizationType" type="OrganizationType" minOccurs="0" maxOccurs="unbounded"/>
    27             </s:sequence>
    28     </s:complexType>
    29     <s:complexType name="OrganizationType" xdb:SQLType="OrganizationType">
    30             <s:sequence minOccurs="0">
    31                     <s:element name="OrganizationID" type="s:string"/>
    32                     <s:element name="Type" type="s:string" nillable="true"/>
    33                     <s:element name="QCDoneStatus" type="s:string" nillable="true"/>
    34                     <s:element name="QCDoneStatusDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    35                     <s:element name="SiteEstablishmentStatus" type="s:string" nillable="true"/>
    36                     <s:element name="SiteEstablishmentStatusDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    37                     <s:element name="IPFNumber" type="s:int"/>
    38                     <s:element name="DUNSNumber" type="s:int"/>
    39                     <s:element name="GUID" type="s:string" nillable="true"/>
    40                     <s:element name="CreatedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    41                     <s:element name="LastModifiedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    42                     <s:element name="RecordStatus" type="s:string" nillable="true"/>
    43                     <s:element name="RecordStatusDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    44                     <s:element name="LegacyCodes" type="ArrayOfLegacyCode" minOccurs="0"/>
    45                     <s:element name="Addresses" type="ArrayOfAddress" minOccurs="0"/>
    46                     <s:element name="ContactMechanisms" type="ArrayOfContactMechanism" minOccurs="0"/>
    47                     <s:element name="Associations" type="ArrayOfAssociation" minOccurs="0"/>
    48             </s:sequence>
    49     </s:complexType>
    50     <s:complexType name="ArrayOfLegacyCode" xdb:SQLType="ArrayOfLegacyCode">
    51             <s:sequence minOccurs="0">
    52                     <s:element name="LegacyCode" type="LegacyCode" minOccurs="0" maxOccurs="unbounded"/>
    53             </s:sequence>
    54     </s:complexType>
    55     <s:complexType name="LegacyCode" xdb:SQLType="LegacyCode">
    56             <s:sequence minOccurs="0">
    57                     <s:element name="Code" type="s:string" nillable="true"/>
    58                     <s:element name="NetworkID" type="s:string"/>
    59                     <s:element name="GUID" type="s:string" nillable="true"/>
    60                     <s:element name="CreatedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    61                     <s:element name="LastModifiedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    62                     <s:element name="RecordStatus" type="s:string" nillable="true"/>
    63                     <s:element name="RecordStatusDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    64             </s:sequence>
    65     </s:complexType>
    66     <s:complexType name="ArrayOfAddress" xdb:SQLType="ArrayOfAddress">
    67             <s:sequence minOccurs="0">
    68                     <s:element name="Address" type="Address" minOccurs="0" maxOccurs="unbounded"/>
    69             </s:sequence>
    70     </s:complexType>
    71     <s:complexType name="Address" xdb:SQLType="Address">
    72             <s:sequence minOccurs="0">
    73                     <s:element name="StreetName1" type="s:string" nillable="true"/>
    74                     <s:element name="StreetName2" type="s:string" nillable="true"/>
    75                     <s:element name="StreetName3" type="s:string" nillable="true"/>
    76                     <s:element name="StreetName4" type="s:string" nillable="true"/>
    77                     <s:element name="CityName" type="s:string" nillable="true"/>
    78                     <s:element name="CityGUID" type="s:string" nillable="true"/>
    79                     <s:element name="CityCreatedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    80                     <s:element name="CityLastModifiedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    81                     <s:element name="CityRecordStatus" type="s:string" nillable="true"/>
    82                     <s:element name="CityRecordStatusDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    83                     <s:element name="StateName" type="s:string" nillable="true"/>
    84                     <s:element name="StateGUID" type="s:string" nillable="true"/>
    85                     <s:element name="StateCreatedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    86                     <s:element name="StateLastModifiedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    87                     <s:element name="StateRecordStatus" type="s:string" nillable="true"/>
    88                     <s:element name="StateRecordStatusDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    89                     <s:element name="CountryName" type="s:string" nillable="true"/>
    90                     <s:element name="CountryCode" type="s:string" nillable="true"/>
    91                     <s:element name="CountryGUID" type="s:string" nillable="true"/>
    92                     <s:element name="CountryCreatedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    93                     <s:element name="CountryLastModifiedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    94                     <s:element name="CountryRecordStatus" type="s:string" nillable="true"/>
    95                     <s:element name="CountryRecordStatusDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    96                     <s:element name="ZipPostalCode" type="s:string" nillable="true"/>
    97                     <s:element name="GUID" type="s:string" nillable="true"/>
    98                     <s:element name="CreatedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    99                     <s:element name="LastModifiedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    100                     <s:element name="RecordStatus" type="s:string" nillable="true"/>
    101                     <s:element name="RecordStatusDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    102                     <s:element name="Type" type="s:string" nillable="true"/>
    103                     <s:element name="TypeOtherSpecify" type="s:string" nillable="true"/>
    104                     <s:element name="InternalOffice" type="s:string" nillable="true"/>
    105                     <s:element name="MailStopCode" type="s:string" nillable="true"/>
    106                     <s:element name="PreferredFlag" type="s:string" nillable="true"/>
    107                     <s:element name="ActiveFromDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    108                     <s:element name="QCDoneStatus" type="s:string" nillable="true"/>
    109                     <s:element name="QCDoneStatusDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    110             </s:sequence>
    111     </s:complexType>
    112     <s:complexType name="ArrayOfContactMechanism" xdb:SQLType="ArrayOfContactMechanism">
    113             <s:sequence minOccurs="0">
    114                     <s:element name="ContactMechanism" type="ContactMechanism" minOccurs="0" maxOccurs="unbounded"/>
    115             </s:sequence>
    116     </s:complexType>
    117     <s:complexType name="ContactMechanism" xdb:SQLType="ContactMechanism">
    118             <s:sequence minOccurs="0">
    119                     <s:element name="ContactType" type="s:string" nillable="true"/>
    120                     <s:element name="ContactTypeOtherSpecify" type="s:string" nillable="true"/>
    121                     <s:element name="ContactValue" type="s:string" nillable="true"/>
    122                     <s:element name="ContactAreaCode" type="s:string" nillable="true"/>
    123                     <s:element name="ContactCountryCallingCode" type="s:int"/>
    124                     <s:element name="ContactTollFreeFlag" type="s:string" nillable="true"/>
    125                     <s:element name="ContactGUID" type="s:string" nillable="true"/>
    126                     <s:element name="ContactCreatedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    127                     <s:element name="ContactLastModifiedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    128                     <s:element name="ContactRecordStatus" type="s:string" nillable="true"/>
    129                     <s:element name="ContactRecordStatusDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    130                     <s:element name="Role" type="s:string" nillable="true"/>
    131                     <s:element name="PhoneExtension" type="s:string" nillable="true"/>
    132                     <s:element name="QCDoneStatus" type="s:string" nillable="true"/>
    133                     <s:element name="QCDoneStatusDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    134                     <s:element name="ActiveFromDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    135                     <s:element name="GUID" type="s:string" nillable="true"/>
    136                     <s:element name="CreatedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    137                     <s:element name="ModifiedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    138                     <s:element name="PreferredFlag" type="s:string" nillable="true"/>
    139                     <s:element name="RecordStatus" type="s:string" nillable="true"/>
    140                     <s:element name="RecordStatusDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    141             </s:sequence>
    142     </s:complexType>
    143     <s:complexType name="ArrayOfAssociation" xdb:SQLType="ArrayOfAssociation">
    144             <s:sequence minOccurs="0">
    145                     <s:element name="Association" type="Association" minOccurs="0" maxOccurs="unbounded"/>
    146             </s:sequence>
    147     </s:complexType>
    148     <s:complexType name="Association" xdb:SQLType="Association">
    149             <s:sequence minOccurs="0">
    150                     <s:element name="Role" type="s:string" nillable="true"/>
    151                     <s:element name="GUID" type="s:string" nillable="true"/>
    152                     <s:element name="QCDoneStatus" type="s:string" nillable="true"/>
    153                     <s:element name="QCDoneStatusDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    154                     <s:element name="CreatedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    155                     <s:element name="LastModifiedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    156                     <s:element name="RecordStatus" type="s:string" nillable="true"/>
    157                     <s:element name="RecordStatusDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    158                     <s:element name="Addresses" type="ArrayOfAddress" minOccurs="0"/>
    159                     <s:element name="ContactMechanisms" type="ArrayOfContactMechanism" minOccurs="0"/>
    160                     <s:element name="Persons" type="ArrayOfPerson" minOccurs="0"/>
    161             </s:sequence>
    162     </s:complexType>
    163     <s:complexType name="ArrayOfPerson" xdb:SQLType="ArrayOfPerson">
    164             <s:sequence minOccurs="0">
    165                     <s:element name="Person" type="Person" minOccurs="0" maxOccurs="unbounded"/>
    166             </s:sequence>
    167     </s:complexType>
    168     <s:complexType name="Person" xdb:SQLType="Person">
    169             <s:sequence minOccurs="0">
    170                     <s:element name="PersonID" type="s:int"/>
    171                     <s:element name="Prefix" type="s:string" nillable="true"/>
    172                     <s:element name="FirstName" type="s:string" nillable="true"/>
    173                     <s:element name="MiddleName" type="s:string" nillable="true"/>
    174                     <s:element name="LastName" type="s:string" nillable="true"/>
    175                     <s:element name="Suffix" type="s:string" nillable="true"/>
    176                     <s:element name="PreferredName" type="s:string" nillable="true"/>
    177                     <s:element name="Gender" type="s:string" nillable="true"/>
    178                     <s:element name="PrimaryLanguage" type="s:string" nillable="true"/>
    179                     <s:element name="GUID" type="s:string" nillable="true"/>
    180                     <s:element name="RecordStatus" type="s:string" nillable="true"/>
    181                     <s:element name="RecordStatusDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    182                     <s:element name="CreatedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    183                     <s:element name="LastModifiedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    184                     <s:element name="QCDoneStatus" type="s:string" nillable="true"/>
    185                     <s:element name="QCDoneStatusDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    186                     <s:element name="PersonDegrees" type="ArrayOfPersonDegree" minOccurs="0"/>
    187                     <s:element name="PersonSpecialties" type="ArrayOfPersonSpecialty" minOccurs="0"/>
    188                     <s:element name="PersonTypes" type="ArrayOfPersonType" minOccurs="0"/>
    189                     <s:element name="Addresses" type="ArrayOfAddress" minOccurs="0"/>
    190                     <s:element name="ContactMechanisms" type="ArrayOfContactMechanism" minOccurs="0"/>
    191                     <s:element name="ImportedDate" type="s:date"/>
    192             </s:sequence>
    193     </s:complexType>
    194     <s:complexType name="ArrayOfPersonDegree" xdb:SQLType="ArrayOfPersonDegree">
    195             <s:sequence minOccurs="0">
    196                     <s:element name="PersonDegree" type="PersonDegree" minOccurs="0" maxOccurs="unbounded"/>
    197             </s:sequence>
    198     </s:complexType>
    199     <s:complexType name="PersonDegree" xdb:SQLType="PersonDegree">
    200             <s:sequence minOccurs="0">
    201                     <s:element name="Code" type="s:string" nillable="true"/>
    202                     <s:element name="Major" type="s:string" nillable="true"/>
    203                     <s:element name="ListingOrder" type="s:int"/>
    204                     <s:element name="GUID" type="s:string" nillable="true"/>
    205                     <s:element name="RecordStatus" type="s:string" nillable="true"/>
    206                     <s:element name="RecordStatusDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    207                     <s:element name="CreatedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    208                     <s:element name="LastModifiedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    209             </s:sequence>
    210     </s:complexType>
    211     <s:complexType name="ArrayOfPersonSpecialty" xdb:SQLType="ArrayOfPersonSpecialty">
    212             <s:sequence minOccurs="0">
    213                     <s:element name="PersonSpecialty" type="PersonSpecialty" minOccurs="0" maxOccurs="unbounded"/>
    214             </s:sequence>
    215     </s:complexType>
    216     <s:complexType name="PersonSpecialty" xdb:SQLType="PersonSpecialty">
    217             <s:sequence minOccurs="0">
    218                     <s:element name="Name" type="s:string" nillable="true"/>
    219                     <s:element name="GUID" type="s:string" nillable="true"/>
    220                     <s:element name="RecordStatus" type="s:string" nillable="true"/>
    221                     <s:element name="RecordStatusDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    222                     <s:element name="CreatedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    223                     <s:element name="LastModifiedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    224             </s:sequence>
    225     </s:complexType>
    226     <s:complexType name="ArrayOfPersonType" xdb:SQLType="ArrayOfPersonType">
    227             <s:sequence minOccurs="0">
    228                     <s:element name="PersonType" type="PersonType" minOccurs="0" maxOccurs="unbounded"/>
    229             </s:sequence>
    230     </s:complexType>
    231     <s:complexType name="PersonType" xdb:SQLType="PersonType">
    232             <s:sequence minOccurs="0">
    233                     <s:element name="Type" type="s:string" nillable="true"/>
    234                     <s:element name="GUID" type="s:string" nillable="true"/>
    235                     <s:element name="RecordStatus" type="s:string" nillable="true"/>
    236                     <s:element name="RecordStatusDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    237                     <s:element name="CreatedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    238                     <s:element name="LastModifiedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    239                     <s:element name="QCDoneStatus" type="s:string" nillable="true"/>
    240                     <s:element name="QCDoneStatusDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    241             </s:sequence>
    242     </s:complexType>
    243     <s:complexType name="ArrayOfOrganizationSynonym" xdb:SQLType="ArrayOfOrganizationSynonym">
    244             <s:sequence minOccurs="0">
    245                     <s:element name="OrganizationSynonym" type="OrganizationSynonym" minOccurs="0" maxOccurs="unbounded"/>
    246             </s:sequence>
    247     </s:complexType>
    248     <s:complexType name="OrganizationSynonym" xdb:SQLType="OrganizationSynonym">
    249             <s:sequence minOccurs="0">
    250                     <s:element name="Name" type="s:string" nillable="true"/>
    251                     <s:element name="GUID" type="s:string" nillable="true"/>
    252                     <s:element name="CreatedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    253                     <s:element name="LastModifiedDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    254                     <s:element name="RecordStatus" type="s:string" nillable="true"/>
    255                     <s:element name="RecordStatusDate" type="s:dateTime" xdb:SQLType="TIMESTAMP(6) WITH TIME ZONE"/>
    256             </s:sequence>
    257     </s:complexType>
    258  </s:schema>';
    259    :xmltext1 :=
    260  '<?xml version="1.0" encoding="WINDOWS-1252"?> <Person xsi:noNamespaceSchemaLocation="mcs.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns
    :xsi="http://www.w3.org/2001/XMLSchema-instance">
    261    <PersonID>100448</PersonID>
    262    <Prefix/>
    263    <FirstName>John</FirstName>
    264    <MiddleName/>
    265    <LastName>Doe</LastName>
    266    <Suffix/>
    267    <PreferredName/>
    268    <Gender/>
    269    <PrimaryLanguage xsi:nil="true"/>
    270    <GUID>ffff-ffff-ffff</GUID>
    271    <RecordStatus>Active</RecordStatus>
    272    <RecordStatusDate>2007-04-29T00:11:50.750000-04:00</RecordStatusDate>
    273    <CreatedDate>2006-06-13T00:57:21.090000-04:00</CreatedDate>
    274    <LastModifiedDate>2007-04-29T00:11:50.770000-04:00</LastModifiedDate>
    275    <QCDoneStatus>Yes</QCDoneStatus>
    276    <QCDoneStatusDate>2006-06-13T00:57:22.977000-04:00</QCDoneStatusDate>
    277    <PersonDegrees>
    278      <PersonDegree>
    279        <Code>B.S.</Code>
    280        <Major xsi:nil="true"/>
    281        <ListingOrder>1</ListingOrder>
    282        <GUID>d01bbcfd-9d48-47bf-818d-9957b907a664</GUID>
    283        <RecordStatus>Active</RecordStatus>
    284        <RecordStatusDate>2006-10-05T10:48:04.430000-04:00</RecordStatusDate>
    285        <CreatedDate>2006-10-05T10:48:06.520000-04:00</CreatedDate>
    286        <LastModifiedDate>2006-10-05T10:48:06.520000-04:00</LastModifiedDate>
    287      </PersonDegree>
    288    </PersonDegrees>
    289    <PersonSpecialties/>
    290    <PersonTypes>
    291      <PersonType>
    292        <Type>Resource Personnel</Type>
    293        <GUID>3049ddcd-3590-4fd9-a534-e2cea5b82c09</GUID>
    294        <RecordStatus>Active</RecordStatus>
    295        <RecordStatusDate>2006-06-13T00:57:22.977000-04:00</RecordStatusDate>
    296        <CreatedDate>2006-06-13T00:57:21.090000-04:00</CreatedDate>
    297        <LastModifiedDate>2007-04-29T00:11:50.817000-04:00</LastModifiedDate>
    298        <QCDoneStatus>Yes</QCDoneStatus>
    299        <QCDoneStatusDate>2006-06-13T00:57:22.977000-04:00</QCDoneStatusDate>
    300      </PersonType>
    301    </PersonTypes>
    302    <Addresses/>
    303    <ContactMechanisms/>
    304    <ImportedDate>2007-04-30</ImportedDate>
    305  </Person>';
    306    :xmltext2 :=
    307  '<?xml version="1.0" encoding="WINDOWS-1252"?> <OrganizationPersonAssoc xsi:noNamespaceSchemaLocation="mcs.xsd" xmlns:xsd="http://www.w3.org/2001
    /XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    308    <Name>Org Name Office</Name>
    309    <LongName>Long Name</LongName>
    310    <Description xsi:nil="true"/>
    311    <FWANumber xsi:nil="true"/>
    312    <GUID>dddd-dddd</GUID>
    313    <CreatedDate>2006-05-18T18:59:01.500000-04:00</CreatedDate>
    314    <LastModifiedDate>2006-05-18T18:59:01.500000-04:00</LastModifiedDate>
    315    <RecordStatus>Active</RecordStatus>
    316    <RecordStatusDate>2006-05-18T18:59:01.500000-04:00</RecordStatusDate>
    317    <OrganizationTypes>
    318      <OrganizationType>
    319        <OrganizationID>30097</OrganizationID>
    320        <Type>Agency</Type>
    321        <QCDoneStatus>Yes</QCDoneStatus>
    322        <QCDoneStatusDate>2006-05-18T18:59:01.513000-04:00</QCDoneStatusDate>
    323        <SiteEstablishmentStatus xsi:nil="true"/>
    324        <SiteEstablishmentStatusDate>0001-01-01T00:00:00.000000-05:00</SiteEstablishmentStatusDate>
    325        <IPFNumber>0</IPFNumber>
    326        <DUNSNumber>0</DUNSNumber>
    327        <GUID>cfe9e9e0-68a3-45c9-81c0-74848523133b</GUID>
    328        <CreatedDate>2006-05-18T18:59:01.513000-04:00</CreatedDate>
    329        <LastModifiedDate>2006-05-18T18:59:01.513000-04:00</LastModifiedDate>
    330        <RecordStatus>Active</RecordStatus>
    331        <RecordStatusDate>2006-05-18T18:59:01.513000-04:00</RecordStatusDate>
    332        <Associations>
    333          <Association>
    334            <Role>Employee</Role>
    335            <GUID>9a9a9a-ababab</GUID>
    336            <QCDoneStatus>Yes</QCDoneStatus>
    337            <QCDoneStatusDate>2006-06-13T01:29:09.030000-04:00</QCDoneStatusDate>
    338            <CreatedDate>2006-06-13T01:29:09.030000-04:00</CreatedDate>
    339            <LastModifiedDate>2006-07-25T15:27:23.783000-04:00</LastModifiedDate>
    340            <RecordStatus>Active</RecordStatus>
    341            <RecordStatusDate>2006-06-13T01:29:09.030000-04:00</RecordStatusDate>
    342            <Addresses>
    343              <Address>
    344                <StreetName1>123 Front St.</StreetName1>
    345                <StreetName2 xsi:nil="true"/>
    346                <StreetName3 xsi:nil="true"/>
    347                <StreetName4 xsi:nil="true"/>
    348                <CityName>City</CityName>
    349                <CityGUID>234234</CityGUID>
    350                <CityCreatedDate>2006-05-08T20:06:45.143000-04:00</CityCreatedDate>
    351                <CityLastModifiedDate>2006-05-08T20:06:45.143000-04:00</CityLastModifiedDate>
    352                <CityRecordStatus>Active</CityRecordStatus>
    353                <CityRecordStatusDate>2006-05-08T20:06:45.143000-04:00</CityRecordStatusDate>
    354                <StateName>New York</StateName>
    355                <StateGUID>9fd469e1-4d4a-4f38-9def-50038e5ecca2</StateGUID>
    356                <StateCreatedDate>2006-04-22T16:09:35.830000-04:00</StateCreatedDate>
    357                <StateLastModifiedDate>2006-04-22T16:09:35.830000-04:00</StateLastModifiedDate>
    358                <StateRecordStatus>Active</StateRecordStatus>
    359                <StateRecordStatusDate>2006-04-22T16:09:35.830000-04:00</StateRecordStatusDate>
    360                <CountryName>United States</CountryName>
    361                <CountryCode>USA</CountryCode>
    362                <CountryGUID>532d35dd-3a49-408a-a416-20c41e9c7997</CountryGUID>
    363                <CountryCreatedDate>2006-04-22T15:30:47.000000-04:00</CountryCreatedDate>
    364                <CountryLastModifiedDate>2006-04-22T15:30:47.000000-04:00</CountryLastModifiedDate>
    365                <CountryRecordStatus>Active</CountryRecordStatus>
    366                <CountryRecordStatusDate>2006-04-22T15:30:47.000000-04:00</CountryRecordStatusDate>
    367                <ZipPostalCode>12345</ZipPostalCode>
    368                <GUID>b2414fa9-7375-4d26-8d76-89a6915d6751</GUID>
    369                <CreatedDate>2006-06-13T01:29:09.030000-04:00</CreatedDate>
    370                <LastModifiedDate>2006-07-29T23:45:17.670000-04:00</LastModifiedDate>
    371                <RecordStatus>Active</RecordStatus>
    372                <RecordStatusDate>2006-06-13T01:29:09.030000-04:00</RecordStatusDate>
    373                <Type>Office</Type>
    374                <TypeOtherSpecify/>
    375                <InternalOffice></InternalOffice>
    376                <MailStopCode/>
    377                <PreferredFlag>Yes</PreferredFlag>
    378                <ActiveFromDate>2006-06-13T01:29:09.000000-04:00</ActiveFromDate>
    379                <QCDoneStatus>Yes</QCDoneStatus>
    380                <QCDoneStatusDate>2006-06-13T01:29:09.030000-04:00</QCDoneStatusDate>
    381              </Address>
    382            </Addresses>
    383            <ContactMechanisms>
    384              <ContactMechanism>
    385                <ContactType>Phone</ContactType>
    386                <ContactTypeOtherSpecify xsi:nil="true"/>
    387                <ContactValue>555-5555</ContactValue>
    388                <ContactAreaCode>555</ContactAreaCode>
    389                <ContactCountryCallingCode>1</ContactCountryCallingCode>
    390                <ContactTollFreeFlag xsi:nil="true"/>
    391                <ContactGUID>123</ContactGUID>
    392                <ContactCreatedDate>2006-06-13T01:29:09.047000-04:00</ContactCreatedDate>
    393                <ContactLastModifiedDate>2007-02-23T16:36:10.260000-05:00</ContactLastModifiedDate>
    394                <ContactRecordStatus>Active</ContactRecordStatus>
    395                <ContactRecordStatusDate>2006-06-13T01:29:09.047000-04:00</ContactRecordStatusDate>
    396                <Role>Business</Role>
    397                <PhoneExtension/>
    398                <QCDoneStatus>Yes</QCDoneStatus>
    399                <QCDoneStatusDate>2006-06-13T01:29:09.047000-04:00</QCDoneStatusDate>
    400                <ActiveFromDate>2006-06-13T01:29:09.000000-04:00</ActiveFromDate>
    401                <GUID>321</GUID>
    402                <CreatedDate>2006-06-13T01:29:09.047000-04:00</CreatedDate>
    403                <ModifiedDate>2006-07-29T23:53:03.323000-04:00</ModifiedDate>
    404                <PreferredFlag>Yes</PreferredFlag>
    405                <RecordStatus>Inactive</RecordStatus>
    406                <RecordStatusDate>2006-07-29T23:53:03.393000-04:00</RecordStatusDate>
    407              </ContactMechanism>
    408              <ContactMechanism>
    409                <ContactType>Email</ContactType>
    410                <ContactTypeOtherSpecify xsi:nil="true"/>
    411                <ContactValue>[email protected]</ContactValue>
    412                <ContactAreaCode xsi:nil="true"/>
    413                <ContactCountryCallingCode>0</ContactCountryCallingCode>
    414                <ContactTollFreeFlag xsi:nil="true"/>
    415                <ContactGUID>ddd</ContactGUID>
    416                <ContactCreatedDate>2006-06-13T01:29:09.047000-04:00</ContactCreatedDate>
    417                <ContactLastModifiedDate>2006-06-13T01:29:09.047000-04:00</ContactLastModifiedDate>
    418                <ContactRecordStatus>Active</ContactRecordStatus>
    419                <ContactRecordStatusDate>2006-06-13T01:29:09.047000-04:00</ContactRecordStatusDate>
    420                <Role>Business</Role>
    421                <PhoneExtension xsi:nil="true"/>
    422                <QCDoneStatus>Yes</QCDoneStatus>
    423                <QCDoneStatusDate>2006-06-13T01:29:09.063000-04:00</QCDoneStatusDate>
    424                <ActiveFromDate>2006-06-13T01:29:09.063000-04:00</ActiveFromDate>
    425                <GUID>111</GUID>
    426                <CreatedDate>2006-06-13T01:29:09.063000-04:00</CreatedDate>
    427                <ModifiedDate>2006-06-13T01:29:09.063000-04:00</ModifiedDate>
    428                <PreferredFlag>Yes</PreferredFlag>
    429                <RecordStatus>Active</RecordStatus>
    430                <RecordStatusDate>2006-06-13T01:29:09.063000-04:00</RecordStatusDate>
    431              </ContactMechanism>
    432            </ContactMechanisms>
    433            <Persons>
    434              <Person>
    435                <PersonID>100448</PersonID>
    436                <Prefix/>
    437                <FirstName>John</FirstName>
    438                <MiddleName/>
    439                <LastName>Doe</LastName>
    440                <Suffix/>
    441                <PreferredName/>
    442                <Gender/>
    443                <PrimaryLanguage xsi:nil="true"/>
    444                <GUID>123</GUID>
    445                <RecordStatus>Active</RecordStatus>
    446                <RecordStatusDate>2007-04-29T00:11:50.750000-04:00</RecordStatusDate>
    447                <CreatedDate>2006-06-13T00:57:21.090000-04:00</CreatedDate>
    448                <LastModifiedDate>2007-04-29T00:11:50.770000-04:00</LastModifiedDate>
    449                <QCDoneStatus>Yes</QCDoneStatus>
    450                <QCDoneStatusDate>2006-06-13T00:57:22.977000-04:00</QCDoneStatusDate>
    451                <PersonTypes>
    452                  <PersonType>
    453                    <Type>Resource Personnel</Type>
    454                    <GUID>3049ddcd-3590-4fd9-a534-e2cea5b82c09</GUID>
    455                    <RecordStatus>Active</RecordStatus>
    456                    <RecordStatusDate>2006-06-13T00:57:22.977000-04:00</RecordStatusDate>
    457                    <CreatedDate>2006-06-13T00:57:21.090000-04:00</CreatedDate>
    458                    <LastModifiedDate>2007-04-29T00:11:50.817000-04:00</LastModifiedDate>
    459                    <QCDoneStatus>Yes</QCDoneStatus>
    460                    <QCDoneStatusDate>2006-06-13T00:57:22.977000-04:00</QCDoneStatusDate>
    461                  </PersonType>
    462                </PersonTypes>
    463              </Person>
    464            </Persons>
    465          </Association>
    466        </Associations>
    467      </OrganizationType>
    468    </OrganizationTypes>
    469    <ImportedDate>2007-04-30</ImportedDate>
    470  </OrganizationPersonAssoc>
    471  ';
    472  end;
    473  /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.00
    SQL> begin
      2    dbms_xmlschema.registerSchema
      3    (
      4        schemaURL => :schemaURL
      5       ,schemaDoc => :xmlSchema
      6       ,local     => TRUE
      7       ,genBean   => false
      8       ,genTypes  => TRUE
      9       ,genTables => TRUE
    10       ,enableHierarchy => DBMS_XMLSCHEMA.ENABLE_HIERARCHY_NONE
    11    );
    12  end;
    13  /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:03.67
    SQL> insert into Person values ( xmltype (:xmltext1))
      2  /
    1 row created.
    Elapsed: 00:00:00.07
    SQL> insert into org_person_assoc values ( xmltype (:xmltext2))
      2  /
    1 row created.
    Elapsed: 00:00:00.03
    SQL> commit
      2  /
    Commit complete.
    Elapsed: 00:00:00.00
    SQL> CREATE OR REPLACE VIEW XML_PERSON_ASSOCIATION
      2  (PERSON)
      3  AS
      4  select
      5  xmlelement("Person",
      6      xmlforest(
      7          extractvalue(value(p),'/Person/PersonID') "PersonID",
      8          extractvalue(value(p),'/Person/Prefix') "Prefix",
      9          extractvalue(value(p),'/Person/FirstName') "FirstName",
    10          extractvalue(value(p),'/Person/MiddleName') "MiddleName",
    11          extractvalue(value(p),'/Person/LastName') "LastName",
    12          extractvalue(value(p),'/Person/Suffix') "Suffix",
    13          extractvalue(value(p),'/Person/PreferredName') "PreferredName",
    14          extractvalue(value(p),'/Person/Gender') "Gender",
    15          extractvalue(value(p),'/Person/PrimaryLanguage') "PrimaryLanguage",
    16          extractvalue(value(p),'/Person/RecordStatus') "RecordStatus",
    17          extractvalue(value(p),'/Person/ImportedDate') "ImportedDate",
    18          (select
    19              xmlagg(
    20                  xmlelement("Association",
    21                      xmlforest(
    22                          extractvalue(value(oa),'/OrganizationPersonAssoc/Name') "Name",
    23                          extractvalue(value(ot),'/OrganizationType/OrganizationID') "OrganizationID",
    24                          extractvalue(value(ot),'/OrganizationType/Type') "OrganizationType",
    25                          extractvalue(value(a),'/Association/Role') "Role",
    26                          extractvalue(value(a),'/Association/RecordStatus') "RecordStatus",
    27                          extractvalue(value(oa),'/OrganizationPersonAssoc/ImportedDate') "ImportedDate"
    28                      ),
    29                      xmlelement("PersonTypes",
    30                          extract(value(per),'/Person/PersonTypes/PersonType')
    31                      ),
    32                      xmlelement("Addresses",
    33                          extract(value(a),'/Association/Addresses/Address')
    34                      ),
    35                      xmlelement("ContactMechanisms",
    36                          extract(value(a),'/Association/ContactMechanisms/ContactMechanism')
    37                      )
    38                  )
    39              )
    40          from org_person_assoc oa,
    41          table(xmlsequence(extract(value(oa),'/OrganizationPersonAssoc/OrganizationTypes/OrganizationType'))) ot,
    42          table(xmlsequence(extract(value(ot),'/OrganizationType/Associations/Association'))) a,
    43          table(xmlsequence(extract(value(a),'/Association/Persons/Person'))) per
    44          where extractvalue(value(per),'/Person/PersonID') = extractvalue(value(p),'/Person/PersonID')
    45          ) "Associations"
    46      )
    47  ) person
    48  from person p
    49  /
    View created.
    Elapsed: 00:00:00.06
    SQL> set autotrace on explain
    SQL> --
    SQL> set long 10000 pages 0 lines 150
    SQL> --
    SQL> select person
      2    from xml_person_association o
      3   where existsnode(person,'/Person/Associations/Association[OrganizationID=30097]')=1
      4  /
    <Person><PersonID>100448</PersonID><FirstName>John</FirstName><LastName>Doe</LastName><RecordStatus>Active</RecordStatus><ImportedDate>2007-04-30</Imp
    ortedDate><Associations><Association><Name>Org Name Office</Name><OrganizationID>30097</OrganizationID><OrganizationType>Agency</OrganizationType><Rol
    e>Employee</Role><RecordStatus>Active</RecordStatus><ImportedDate>2007-04-30</ImportedDate><PersonTypes><PersonType>
      <Type>Resource Personnel</Type>
      <GUID>3049ddcd-3590-4fd9-a534-e2cea5b82c09</GUID>
      <RecordStatus>Active</RecordStatus>
      <RecordStatusDate>2006-06-13T00:57:22.977000-04:00</RecordStatusDate>
      <CreatedDate>2006-06-13T00:57:21.090000-04:00</CreatedDate>
      <LastModifiedDate>2007-04-29T00:11:50.817000-04:00</LastModifiedDate>
      <QCDoneStatus>Yes</QCDoneStatus>
      <QCDoneStatusDate>2006-06-13T00:57:22.977000-04:00</QCDoneStatusDate>
    </PersonType>
    </PersonTypes><Addresses><Address>
      <StreetName1>123 Front St.</StreetName1>
      <StreetName2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
      <StreetName3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
      <StreetName4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
      <CityName>City</CityName>
      <CityGUID>234234</CityGUID>
      <CityCreatedDate>2006-05-08T20:06:45.143000-04:00</CityCreatedDate>
      <CityLastModifiedDate>2006-05-08T20:06:45.143000-04:00</CityLastModifiedDate>
      <CityRecordStatus>Active</CityRecordStatus>
      <CityRecordStatusDate>2006-05-08T20:06:45.143000-04:00</CityRecordStatusDate>
      <StateName>New York</StateName>
      <StateGUID>9fd469e1-4d4a-4f38-9def-50038e5ecca2</StateGUID>
      <StateCreatedDate>2006-04-22T16:09:35.830000-04:00</StateCreatedDate>
      <StateLastModifiedDate>2006-04-22T16:09:35.830000-04:00</StateLastModifiedDate>
      <StateRecordStatus>Active</StateRecordStatus>
      <StateRecordStatusDate>2006-04-22T16:09:35.830000-04:00</StateRecordStatusDate>
      <CountryName>United States</CountryName>
      <CountryCode>USA</CountryCode>
      <CountryGUID>532d35dd-3a49-408a-a416-20c41e9c7997</CountryGUID>
      <CountryCreatedDate>2006-04-22T15:30:47.000000-04:00</CountryCreatedDate>
      <CountryLastModifiedDate>2006-04-22T15:30:47.000000-04:00</CountryLastModifiedDate>
      <CountryRecordStatus>Active</CountryRecordStatus>
      <CountryRecordStatusDate>2006-04-22T15:30:47.000000-04:00</CountryRecordStatusDate>
      <ZipPostalCode>12345</ZipPostalCode>
      <GUID>b2414fa9-7375-4d26-8d76-89a6915d6751</GUID>
      <CreatedDate>2006-06-13T01:29:09.030000-04:00</CreatedDate>
      <LastModifiedDate>2006-07-29T23:45:17.670000-04:00</LastModifiedDate>
      <RecordStatus>Active</RecordStatus>
      <RecordStatusDate>2006-06-13T01:29:09.030000-04:00</RecordStatusDate>
      <Type>Office</Type>
      <TypeOtherSpecify/>
      <InternalOffice/>
      <MailStopCode/>
      <PreferredFlag>Yes</PreferredFlag>
      <ActiveFromDate>2006-06-13T01:29:09.000000-04:00</ActiveFromDate>
      <QCDoneStatus>Yes</QCDoneStatus>
      <QCDoneStatusDate>2006-06-13T01:29:09.030000-04:00</QCDoneStatusDate>
    </Address>
    </Addresses><ContactMechanisms><ContactMechanism>
      <ContactType>Phone</ContactType>
      <ContactTypeOtherSpecify xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
      <ContactValue>555-5555</ContactValue>
      <ContactAreaCode>555</ContactAreaCode>
      <ContactCountryCallingCode>1</ContactCountryCallingCode>
      <ContactTollFreeFlag xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
      <ContactGUID>123</ContactGUID>
      <ContactCreatedDate>2006-06-13T01:29:09.047000-04:00</ContactCreatedDate>
      <ContactLastModifiedDate>2007-02-23T16:36:10.260000-05:00</ContactLastModifiedDate>
      <ContactRecordStatus>Active</ContactRecordStatus>
      <ContactRecordStatusDate>2006-06-13T01:29:09.047000-04:00</ContactRecordStatusDate>
      <Role>Business</Role>
      <PhoneExtension/>
      <QCDoneStatus>Yes</QCDoneStatus>
      <QCDoneStatusDate>2006-06-13T01:29:09.047000-04:00</QCDoneStatusDate>
      <ActiveFromDate>2006-06-13T01:29:09.000000-04:00</ActiveFromDate>
      <GUID>321</GUID>
      <CreatedDate>2006-06-13T01:29:09.047000-04:00</CreatedDate>
      <ModifiedDate>2006-07-29T23:53:03.323000-04:00</ModifiedDate>
      <PreferredFlag>Yes</PreferredFlag>
      <RecordStatus>Inactive</RecordStatus>
      <RecordStatusDate>2006-07-29T23:53:03.393000-04:00</RecordStatusDate>
    </ContactMechanism>
    <ContactMechanism>
      <ContactType>Email</ContactType>
      <ContactTypeOtherSpecify xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
      <ContactValue>[email protected]</ContactValue>
      <ContactAreaCode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
      <ContactCountryCallingCode>0</ContactCountryCallingCode>
      <ContactTollFreeFlag xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
      <ContactGUID>ddd</ContactGUID>
      <ContactCreatedDate>2006-06-13T01:29:09.047000-04:00</ContactCreatedDate>
      <ContactLastModifiedDate>2006-06-13T01:29:09.047000-04:00</ContactLastModifiedDate>
      <ContactRecordStatus>Active</ContactRecordStatus>
      <ContactRecordStatusDate>2006-06-13T01:29:09.047000-04:00</ContactRecordStatusDate>
      <Role>Business</Role>
      <PhoneExtension xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
      <QCDoneStatus>Yes</QCDoneStatus>
      <QCDoneStatusDate>2006-06-13T01:29:09.063000-04:00</QCDoneStatusDate>
      <ActiveFromDate>2006-06-13T01:29:09.063000-04:00</ActiveFromDate>
      <GUID>111</GUID>
      <CreatedDate>2006-06-13T01:29:09.063000-04:00</CreatedDate>
      <ModifiedDate>2006-06-13T01:29:09.063000-04:00</ModifiedDate>
      <PreferredFlag>Yes</PreferredFlag>
      <RecordStatus>Active</RecordStatus>
      <RecordStatusDate>2006-06-13T01:29:09.063000-04:00</RecordStatusDate>
    </ContactMechanism>
    </ContactMechanisms></Association></Associations></Person>
    Elapsed: 00:00:00.42
    Execution Plan
    Plan hash value: 95656148
    | Id  | Operation                        | Name                           | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                 |                                |     1 | 18040 |     9   (0)| 00:00:01 |
    |   1 |  SORT AGGREGATE                  |                                |     1 | 10096 |            |          |
    |   2 |   TABLE ACCESS BY INDEX ROWID    | SYS_NT32zHSpCZQ9ynComtqqKsrw== |     1 | 10096 |     2   (0)| 00:00:01 |
    |*  3 |    INDEX RANGE SCAN              | SYS_C009300                    |     1 |       |     2   (0)| 00:00:01 |
    |   4 |    SORT AGGREGATE                |                                |     1 | 48284 |            |          |
    |   5 |     TABLE ACCESS BY INDEX ROWID  | SYS_NTjbkXqKq3S96fbEOM3Qs5Gg== |     1 | 48284 |     2   (0)| 00:00:01 |
    |*  6 |      INDEX RANGE SCAN            | SYS_C009296                    |     1 |       |     2   (0)| 00:00:01 |
    |   7 |      SORT AGGREGATE              |                                |     1 | 28187 |            |          |
    |   8 |       TABLE ACCESS BY INDEX ROWID| SYS_NTm2nBfKKNSGm6hs2e1Z0w/A== |     1 | 28187 |     2   (0)| 00:00:01 |
    |*  9 |        INDEX RANGE SCAN          | SYS_C009297                    |     1 |       |     2   (0)| 00:00:01 |
    |  10 |  SORT AGGREGATE                  |                                |     1 | 13910 |            |          |
    |  11 |   NESTED LOOPS                   |                                |     1 | 13910 |     6   (0)| 00:00:01 |
    |  12 |    NESTED LOOPS                  |                                |     1 |  8131 |     5   (0)| 00:00:01 |
    |  13 |     NESTED LOOPS                 |                                |     1 |  4097 |     4   (0)| 00:00:01 |
    |* 14 |      TABLE ACCESS FULL           | SYS_NT7Erd/G5iSPWX9w20Z5cNRg== |     1 |    43 |     3   (0)| 00:00:01 |
    |* 15 |      TABLE ACCESS BY INDEX ROWID | SYS_NTQWY/m3uES5GM7AByRclr8A== |     1 |  4054 |     1   (0)| 00:00:01 |
    |* 16 |       INDEX UNIQUE SCAN          | SYS_C009310                    |     1 |       |     0   (0)| 00:00:01 |
    |* 17 |     TABLE ACCESS BY INDEX ROWID  | SYS_NTTiDHMvB7RbSEfNxho66yQg== |     1 |  4034 |     1   (0)| 00:00:01 |
    |* 18 |      INDEX UNIQUE SCAN           | SYS_C009314                    |     1 |       |     0   (0)| 00:00:01 |
    |  19 |    TABLE ACCESS BY INDEX ROWID   | ORG_PERSON_ASSOC               |     1 |  5779 |     1   (0)| 00:00:01 |
    |* 20 |     INDEX UNIQUE SCAN            | SYS_C009320                    |     1 |       |     0   (0)| 00:00:01 |
    |* 21 |  FILTER                          |                                |       |       |            |          |
    |  22 |   TABLE ACCESS FULL              | PERSON                         |     1 | 18040 |     3   (0)| 00:00:01 |
    |  23 |   NESTED LOOPS                   |                                |       |       |            |          |
    |  24 |    NESTED LOOPS                  |                                |     1 |  5893 |     6   (0)| 00:00:01 |
    |  25 |     NESTED LOOPS                 |                                |     1 |  2125 |     5   (0)| 00:00:01 |
    |  26 |      NESTED LOOPS                |                                |     1 |    93 |     4   (0)| 00:00:01 |
    |* 27 |       TABLE ACCESS FULL          | SYS_NT7Erd/G5iSPWX9w20Z5cNRg== |     1 |    43 |     3   (0)| 00:00:01 |
    |* 28 |       TABLE ACCESS BY INDEX ROWID| SYS_NTQWY/m3uES5GM7AByRclr8A== |     1 |    50 |     1   (0)| 00:00:01 |
    |* 29 |        INDEX UNIQUE SCAN         | SYS_C009310                    |     1 |       |     0   (0)| 00:00:01 |
    |* 30 |      TABLE ACCESS BY INDEX ROWID | SYS_NTTiDHMvB7RbSEfNxho66yQg== |     1 |  2032 |     1   (0)| 00:00:01 |
    |* 31 |       INDEX UNIQUE SCAN          | SYS_C009314                    |     1 |       |     0   (0)| 00:00:01 |
    |* 32 |     INDEX UNIQUE SCAN            | SYS_C009320                    |     1 |       |     0   (0)| 00:00:01 |
    |  33 |    TABLE ACCESS BY INDEX ROWID   | ORG_PERSON_ASSOC               |     1 |  3768 |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       3 - access("NESTED_TABLE_ID"=:B1)
       6 - access("NESTED_TABLE_ID"=:B1)
       9 - access("NESTED_TABLE_ID"=:B1)
      14 - filter("SYS_NC_TYPEID$" IS NOT NULL AND "PersonID"=:B1)
      15 - filter("SYS_NC_TYPEID$" IS NOT NULL)
      16 - access("NESTED_TABLE_ID"="SYS_ALIAS_1"."SYS_NC0002700028$")
      17 - filter("SYS_NC_TYPEID$" IS NOT NULL)
      18 - access("NESTED_TABLE_ID"="SYS_ALIAS_0"."SYS_NC0003700038$")
      20 - access("NESTED_TABLE_ID"="OA"."SYS_NC0002100022$")
      21 - filter( EXISTS (SELECT 0 FROM "XDBTEST"."SYS_NT7Erd/G5iSPWX9w20Z5cNRg=="
                  "SYS_ALIAS_1","XDBTEST"."SYS_NTQWY/m3uES5GM7AByRclr8A=="
                  "SYS_ALIAS_3","XDBTEST"."SYS_NTTiDHMvB7RbSEfNxho66yQg==" "SYS_ALIAS_0","XDBTEST"."ORG_PERSON_ASSOC" "OA"
                  WHERE "SYS_ALIAS_0"."NESTED_TABLE_ID"="OA"."SYS_NC0002100022$" AND
                  "SYS_ALIAS_1"."NESTED_TABLE_ID"="SYS_ALIAS_0"."SYS_NC0003700038$" AND "SYS_ALIAS_0"."SYS_NC_TYPEID$" IS
                  NOT NULL AND TO_NUMBER("SYS_ALIAS_0"."OrganizationID")=30097 AND
                  "SYS_ALIAS_4"."NESTED_TABLE_ID"="SYS_ALIAS_1"."SYS_NC0002700028$" AND "SYS_ALIAS_1"."SYS_NC_TYPEID$" IS
                  NOT NULL AND "SYS_ALIAS_4"."SYS_NC_TYPEID$" IS NOT NULL AND "SYS_ALIAS_4"."PersonID"=:B1))
      27 - filter("SYS_ALIAS_4"."SYS_NC_TYPEID$" IS NOT NULL AND "SYS_ALIAS_4"."PersonID"=:B1)
      28 - filter("SYS_ALIAS_1"."SYS_NC_TYPEID$" IS NOT NULL)
      29 - access("SYS_ALIAS_4"."NESTED_TABLE_ID"="SYS_ALIAS_1"."SYS_NC0002700028$")
      30 - filter("SYS_ALIAS_0"."SYS_NC_TYPEID$" IS NOT NULL AND
                  TO_NUMBER("SYS_ALIAS_0"."OrganizationID")=30097)
      31 - access("SYS_ALIAS_1"."NESTED_TABLE_ID"="SYS_ALIAS_0"."SYS_NC0003700038$")
      32 - access("SYS_ALIAS_0"."NESTED_TABLE_ID"="OA"."SYS_NC0002100022$")
    Note
       - dynamic sampling used for this statement
    SQL> select extract(person,'/Person/Associations/Association')
      2    from xml_person_association o
      3   where existsnode(person,'/Person/Associations/Association[OrganizationID=30097]')=1
      4  /
    <Association><Name>Org Name Office</Name><OrganizationID>30097</OrganizationID><OrganizationType>Agency</OrganizationType><Role>Employee</Role><Record
    Status>Active</RecordStatus><ImportedDate>2007-04-30</ImportedDate><PersonTypes><PersonType><Type>Resource Personnel</Type><GUID>3049ddcd-3590-4fd9-a5
    34-e2cea5b82c09</GUID><RecordStatus>Active</RecordStatus><RecordStatusDate>2006-06-13T00:57:22.977000-04:00</RecordStatusDate><CreatedDate>2006-06-13T
    00:

  • Problem with XDB functions

    Hello.
    We have problems exectuting this SQL script with Oracle XE. It seems that the system cannot find the "dbms_xdb.deleteresource" and "dbms_xdb.setacl" functions. We are trying to execute the script from XE web interface.
    We have another question: is it possible to save or serialize the XML results onto file system (so not in /public folder) in order to be used by other applications ?
    Below is the script execution result.
    Can anyone help on these issues ?
    Thank you in advance for helping.
    Regards.
    Damiano
    create table bck_table as select     "COURSE"."COURSE_ID" as "COURSE_ID",
         "COURSE"."COURSE_NAME" as "COURSE_NAME",
         "COURSE"."COURSE_PRIMARY" as "COURSE_PRIMARY"
    from     "COURSE" "COURSE"
    Table created. 2.36 seconds
    create view bck_view of xmltype
    with object id ('COURSE') as
    select xmlElement
    "Table", xmlAgg
         xmlElement
         "Row", xmlForest (COURSE_ID,COURSE_NAME,COURSE_PRIMARY)     
    from bck_table
    View created. 2.30 seconds
    declare
    res boolean;
    begin
    res:=dbms_xdb.deleteresource('/public/portate.xml');
    commit;
    end;
    ORA-06550: line 4, column 14: PLS-00222: no function with name 'DELETERESOURCE' exists in this scope ORA-06550: line 4, column 9: PL/SQL: Statement ignored
    declare
         xmlRef REF XMLTYPE;
         res boolean;
    begin
         select ref(x) into xmlREF from bck_view x;
         res:=dbms_xdb.createResource('/public/portate.xml',xmlREF);
    commit;
    end;
    ORA-31003: Parent /public/ already contains child entry portate.xml
    declare
    res boolean;
    begin
    res:=dbms_xdb.setacl('/public/portate.xml', '/sys/acls/all_owner_acl.xml');
    commit;
    end;
    ORA-06550: line 4, column 14: PLS-00222: no function with name 'SETACL' exists in this scope ORA-06550: line 4, column 9: PL/SQL: Statement ignored
    drop table bck_table
    Table dropped. 4.30 seconds
    drop view bck_view
    View dropped. 1.45 seconds

    Thank you for helping.
    I have corrected the code but now the result is this one:
    create table bck_table as select     "COURSE"."COURSE_ID" as "COURSE_ID",
         "COURSE"."COURSE_NAME" as "COURSE_NAME",
         "COURSE"."COURSE_PRIMARY" as "COURSE_PRIMARY"
    from     "COURSE" "COURSE"
    Table created. 0.48 seconds
    create view bck_view of xmltype
    with object id ('COURSE') as
    select xmlElement
    "Table", xmlAgg
         xmlElement
         "Row", xmlForest (COURSE_ID,COURSE_NAME,COURSE_PRIMARY)     
    from bck_table
    View created. 0.75 seconds
    begin
    dbms_xdb.deleteresource('/public/portate.xml');
    commit;
    end;
    ORA-31018: Error deleting XML document ORA-00942: table or view does not exist
    declare
         xmlRef REF XMLTYPE;
         res boolean;
    begin
         select ref(x) into xmlREF from bck_view x;
         res:=dbms_xdb.createResource('/public/portate.xml',xmlREF);
    commit;
    end;
    ORA-31003: Parent /public/ already contains child entry portate.xml
    begin
    dbms_xdb.setacl('/public/portate.xml', '/sys/acls/all_owner_acl.xml');
    commit;
    end;
    ORA-01001: invalid cursor ORA-00902: invalid datatype
    drop table bck_table
    Table dropped. 0.84 seconds
    drop view bck_view
    View dropped. 1.26 seconds
    It seems that the system is not able to delete the XML resource, but if I go to http://127.0.0.1:8080/public/ I see "portate.xml" file. In general, where can I find information on managing / exporting / importing XML data with Oracle Express ?
    Bye.
    Damiano

  • XML-Type and reference to unavailable DTD causes validation problems

    Hi,
    I'm fairly new to Oracle's XML features. I've created a view that produces XML from a number of tables. The resulting XML is used to be stored on a web site for download by customers (this is a manual process about once a week via a CMS). It contains a reference to a DTD that is available on the web server, too. This XML must also be stored in the Oracle database. The problem is that the Oracle Server is not allowed to access any web site (Oracle server is in inhouse network with no access allowed to the world outside). So I can't store the XML in an XML-type column, as the Oracle server wants to validate the XML against the referenced DTD. There is an option not to validate the XML. But then I get the error when I try to access the XML afterwards. So up to now I use a CLOB column to store the XML, but then I lose all the benefits of an XML-type column. Is there any workaround?
    TIA,
    Stefan

    In 10.2.0.2.0 The following works
    SQL> drop table TEST_XML
      2  /
    Table dropped.
    SQL> create table TEST_XML (
      2     XML_SEQ number(10) not NULL,
      3     XML_DOC XMLType not NULL
      4  )
      5  /
    Table created.
    SQL> drop sequence TEST_XML_SEQ
      2  /
    Sequence dropped.
    SQL> create sequence TEST_XML_SEQ
      2  /
    Sequence created.
    SQL> create or replace view V_EMP_XML as select
      2         -- Processing Instruction
      3         '<?xml version="1.0" encoding="ISO-8859-1"?>' ||
      4         -- DTD reference
      5         '<!DOCTYPE employees SYSTEM "http://myserver/dtd/employees.dtd">' ||
      6         SYS.XMLTYPE.getClobVal(
      7            XMLElement("employees",
      8               (select XMLAgg(
      9                          XMLElement("emp",
    10                             XMLAttributes(
    11                                e.EMPNO as "empno",
    12                                e.DEPTNO as "deptno"
    13                             ),
    14                             XMLElement("ename", e.ENAME),
    15                             XMLElement("job", e.JOB),
    16                             XMLElement("salary", e.SAL),
    17                             XMLElement("hiredate", to_char(e.HIREDATE, 'YYYY-MM-DD'))
    18                          )
    19                       order by e.EMPNO
    20                       )
    21                from   SCOTT.EMP e
    22               )
    23            )
    24         ) as XML_DOC
    25  from   DUAL
    26  /
    View created.
    SQL>
    SQL> insert into TEST_XML
      2  (
      3    XML_SEQ,
      4    XML_DOC
      5  )
      6  select TEST_XML_SEQ.NEXTVAL,
      7         XMLType(v.XML_DOC, NULL, 1, 1)
      8  from   V_EMP_XML v
      9  /
    1 row created.
    SQL> select t.XML_DOC.getClobVal() as RESULT
      2  from   TEST_XML t
      3  where  t.XML_SEQ = 1
      4  /
    RESULT
    <?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE employees SYSTEM "http://my
    SQL> select extract(t.XML_DOC, '//emp[@deptno=20]').getClobVal() as RESULT
      2  from   TEST_XML t
      3  where  t.XML_SEQ = 1
      4  /
    ERROR:
    ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00202: could not open "http://myserver/dtd/employees.dtd" (error 101)
    Error at line 1
    no rows selected
    SQL> alter session set events ='31156 trace name context forever, level 2'
      2  /
    Session altered.
    SQL> select extract(t.XML_DOC, '//emp[@deptno=20]').getClobVal() as RESULT
      2  from   TEST_XML t
      3  where  t.XML_SEQ = 1
      4  /
    RESULT
    <emp empno="7369" deptno="20"><ename>SMITH</ename><job>CLERK</job><salary>800</s
    SQL>

  • XmlAgg Order By in SQL Statement vs Stored Procedure - 9.2.0.3.0

    Hi All,
    I'm having a problem with the XMLAgg function's ORDER BY clause after upgrading to 9.2.0.3.0.
    I'm finding that I can succesfully execute a SQL statement with the XMLAgg ORDER BY clause, but cannot compile a stored procedure using ORDER BY. Below are two examples executing against the SCOTT Schema. They use the same code, except one is contained in a procedure.
    I'm running 9.2.0.3.0 on Windows XP Pro, SP1
    Plain SQL Statement (executes correctly):
    SELECT
    XMLElement("test",
    XMLAgg(
    XMLElement("element",
    XMLAttributes(Scott.Emp.Ename as "ename", Scott.Emp.Empno as "enum")
    ) --xmlElement element
    ORDER BY Scott.Emp.Ename desc
    ) --XmlAgg
    ).getClobVal() --xmlElement test
    as TestXML
    from Scott.Emp;
    Stored Procedure:
    create or replace procedure zorder(TestXML OUT clob) is
    begin
    SELECT
    XMLElement("test",
    XMLAgg(
    XMLElement("element",
    XMLAttributes(Scott.Emp.Ename as "ename", Scott.Emp.Empno as "enum")
    ) --xmlElement element
    ORDER BY Scott.Emp.Ename desc
    ) --XmlAgg
    ).getClobVal() --xmlElement test
    into TestXML
    from Scott.Emp;
    end zorder;
    I get the following errors when attempting to compile the stored procedure:
    7 PLS-00306: wrong number of types or arguments in call to 'XMLAGG'
    7 PL/SQL: ORA-00904: "XMLAGG": invalid identifier
    5 PL/SQL: SQL Statement ignored
    Does anybody know why this code executes correctly in a SQL statement, but fails in a procedure? Is the Order By clause not available in a procedure? I need to get this functionality working in the procedure.
    Thanks,
    Brian

    A good simple workaround (that doesn't require runtime parsing) is to simply sub-query:
    SELECT
    XMLElement("test",
        XMLAgg(
            XMLElement(
                "element",
                XMLAttributes(Scott.Emp.Ename as "ename", Scott.Emp.Empno as "enum")
            ) --xmlElement element
        ) --XmlAgg
    ).getClobVal() --xmlElement test
    into TestXML
    from (
        SELECT Ename,Empno
        FROM Scott.Emp
        ORDER BY Scott.Emp.Ename desc

  • XMLAGG cannot work in PL/SQL in UTL_FILE

    I developed a simple xml file generation procedure from my purchase order master and detail tables in my database.
    query:
    SELECT XMLELEMENT("OrderMessage", XMLATTRIBUTES('updateorder' as "messageType"),
    XMLELEMENT("MessageHeader", XMLATTRIBUTES(e.version as "version",s_timestamp as "payloadId" ,
    c_timestamp as "timeStamp" ,e.index1 as "senderName"
    ,e.index2 as "senderComponent",e.documentReferenceId as "documentReferenceId"
    ,e.singleTransaction as "singleTransaction"),
    XMLELEMENT ( "HeaderIndexedAttribute", XMLATTRIBUTES('0' as "index", e.index0 as "content")),
    XMLELEMENT ( "HeaderIndexedAttribute", XMLATTRIBUTES('1' as "index", e.senderName as "content")),
    XMLELEMENT ( "HeaderIndexedAttribute", XMLATTRIBUTES('2' as "index", e.senderComponent as "content")),
    XMLELEMENT ( "HeaderIndexedAttribute", XMLATTRIBUTES('3' as "index", e.index3 as "content")))
    ,XMLELEMENT("Order", XMLATTRIBUTES(e.closed as "closed",e.orderNumber as "orderNumber",e.ordertype as "orderType",e.uniqueBusinessKey as "uniqueBusinessKey",'SOA+' as "handlingCode")
    , (SELECT XMLAGG(XMLELEMENT ("OrderLine", XMLATTRIBUTES (f.lineNumber as "lineNumber"),
    XMLELEMENT ( "OrderLineMilestone", XMLATTRIBUTES(f.scheduledDateTime as "scheduledDateTime")),
    XMLELEMENT ( "IndexedAttribute", XMLATTRIBUTES('0' as "index", f.extAmt as "content")) ))
    FROM PO_DETAIL_TEMP f where f.PAYLOADID = po_payloadId)
    , XMLELEMENT ( "Buyer", XMLATTRIBUTES(e.BUYERID as "Id", e.BUYERPARTYNAME as "PartyName", e.BUYERROLE as "Role"))
    )).getClobVal() into v_xml
    FROM PO_MASTER_TEMP e
    where e.PAYLOADID = po_payloadId;
    Utl_File.Put_line(v_file, '<!DOCTYPE OrderMessage SYSTEM "OrderMessage.dtd">');
    WHILE v_more LOOP
    Utl_File.Put(v_file, Substr(v_xml, 1, 32767));
    IF Length(v_xml) > 32767 THEN
    v_xml := Substr(v_xml, 32768);
    ELSE
    v_more := FALSE;
    END IF;
    END LOOP;
    it has displayed this error
    ERROR at line 1:
    ORA-29282: invalid file ID
    ORA-06512: at "SYS.UTL_FILE", line 18
    ORA-06512: at "SYS.UTL_FILE", line 562
    ORA-06512: at "PLANAR.SEND_SO_POSITIVE", line 82
    ORA-29285: file write error
    ORA-06512: at line 1
    the bolded portion is the one giving me problem. i don't understand the logic of this error. if I use SYS_XMLAGG instead of XMLAGG, it writes into the xml file perfectly but it will write a <ROWSET> tag into the file too which isn't needed. I have been running this query in sqlplus directly without problem, only when I use it in pl/sql by storing in a blob and inserting into the file will give me the error.
    i have checked the code for the UTL_FILE and it's fine.
    I have looked through XML Database Developer’s Guide - Oracle XML DB manual and this is what i have found for XMLAGG
    XMLAgg() function is similar to the SYS_XMLAGG() function except that it returns
    a forest of nodes, and does not take the XMLFormat() parameter. This function can
    be used to concatenate XMLType instances across multiple rows. It also allows an
    optional ORDER BY clause to order the XML values being aggregated.
    The point is I don't understand how come query using XML_AGG will give me error when both of queriess result are stored as a blob which shouldn't give me any problem.
    Thanks in advance for any help or suggestion. Any alternatives suggestions are welcome too.

    Simon
    Not sure, never used UTL_FILE myself... I assume V_XML is a CLOB and not a BLOB. The output of getClobVal() will be a CLOB in the database character set, unless it's AL32UTF8 in which case the CLOB will be UCS2. Also, you're sure it's got nothing to do with the length of the generated document.
    I assume that you are writing to the file system so that someother product / process can access the file without connecting to the database. Have you considered placing the file (or a logical pointer to the generated docuemnt) in the XML DB repos, and having the other other product / process access it via FTP or HTTP.
    I tried the following
    SQL> create or replace procedure printXMLToFile(xmlContent XMLType, targetDirectory varchar2, Filena
    me VARCHAR2, CharsetName Varchar2)
    2 is
    3 fHandle utl_file.File_Type;
    4 xmlText CLOB := xmlContent.getClobVal();
    5 offset binary_integer := 1;
    6 linesize binary_integer := 32767;
    7 xmlTextSize binary_integer := dbms_lob.getLength(xmlText);
    8 buffer varchar2(32767);
    9 begin
    10 dbms_output.put_line('Text Size = ' || xmlTextSize);
    11 fhandle := utl_file.fopen(targetDirectory,Filename,'w',linesize);
    12 while offset <= xmlTextSize loop
    13 dbms_output.put_line('Offset = ' || offset);
    14 buffer := dbms_lob.substr(xmlText, linesize, offset);
    15 offset := offset + length(buffer);
    16 utl_file.put_line(fHandle, buffer);
    17 end loop;
    18 utl_file.fclose(fhandle);
    19 end;
    20 /
    Procedure created.
    SQL>
    SQL> create or replace directory temp as 'c:\temp';
    Directory created.
    SQL>
    SQL> set Serveroutput on
    SQL>
    SQL> declare
    2 xml xmltype;
    3 begin
    4 select xmlElement("PurchaseOrders",xmlagg(object_value))
    5 into XML
    6 from PURCHASEORDER;
    7 printXMLtoFile(xml,'TEMP','PurchaseOrders.xml','AL32UTF8');
    8 end;
    9 /
    Text Size = 445056
    Offset = 1
    Offset = 8192
    Offset = 16383
    Offset = 24574
    Offset = 32765
    Offset = 40956
    Offset = 49147
    Offset = 57338
    Offset = 65529
    Offset = 73720
    Offset = 81911
    Offset = 90102
    Offset = 98293
    Offset = 106484
    Offset = 114675
    Offset = 122866
    Offset = 131057
    Offset = 139248
    Offset = 147439
    Offset = 155630
    Offset = 163821
    Offset = 172012
    Offset = 180203
    Offset = 188394
    Offset = 196585
    Offset = 204776
    Offset = 212967
    Offset = 221158
    Offset = 229349
    Offset = 237540
    Offset = 245731
    Offset = 253922
    Offset = 262113
    Offset = 262145
    PL/SQL procedure successfully completed.
    Which is bizare... How did it exit the loop at 262145?
    I did notice another problem with the generated output. put_line put's a CR/LF into the file, if the CR/LF appears in the middle of a tag this makes the generated XML File invalid..

  • XMLAGG giving ORA-19011 when creating CDATA with large embedded XML

    What I'm trying to achieve is to embed XML (XMLTYPE return type) inside a CDATA block. However, I'm receiving "ORA-19011: Character string buffer too small" when generating large amounts of information within the CDATA block using XMLCDATA within an XMLAGG function.
    Allow me to give a step by step explanation through the thought process.
    h4. Creating the inner XML element
    For example, suppose I have the subquery below
    select
        XMLELEMENT("InnerElement",DUMMY) as RESULT
    from dual
    ;I would get the following.
    RESULT                           
    <InnerElement>X</InnerElement>h4. Creating outer XML element, embedding inner XML element in CDATA
    Now, if I my desire were to embed XML inside a CDATA block, that's within another XML element, I can achieve it by doing so
    select
        XMLELEMENT("OuterElement",
            XMLCDATA(XML_RESULT)
        ) XML_IN_CDATA_RESULT
    FROM
    (select
        XMLELEMENT("InnerElement",DUMMY) as XML_RESULT
    from dual)
    ;This gets exactly what I want, embedding XML into CDATA block, and CDATA block is in an XML element.
    XML_IN_CDATA_RESULT                                                       
    <OuterElement><![CDATA[<InnerElement>X</InnerElement>]]></OuterElement>    So far so good. But the real-world dataset naturally isn't that tiny. We'd have more than one record. For reporting, I'd like to put all the <OuterElement> under a XML root.
    h4. Now, I want to put that data in XML root element called <Root>, and aggregate all the <OuterElement> under it.
    select
        XMLELEMENT("Root",
            XMLAGG(
                XMLELEMENT("OuterElement",
                    XMLCDATA(INNER_XML_RESULT)
    FROM
        (select
             XMLELEMENT("InnerElement",DUMMY) as INNER_XML_RESULT
         from dual)
    ;And to my excitement, I get what I want..
    <Root>
        <OuterElement><![CDATA[<InnerElement>X</InnerElement>]]></OuterElement>
        <OuterElement><![CDATA[<InnerElement>Y</InnerElement>]]></OuterElement>
        <OuterElement><![CDATA[<InnerElement>Z</InnerElement>]]></OuterElement>
    </Root>  But... like the real world again... the content of <InnerElement> isn't always so small and simple.
    h4. The problem comes when <InnerElement> contains lots and lots of data.
    When attempting to generate large XML, XMLAGG complains the following:
    ORA-19011: Character string buffer too smallThe challenge is to keep the XML formatting of <InnerElement> within CDATA. A particular testing tool I'm using parses XML out of a CDATA block. I'm hoping to use [Oracle] SQL to generate a test suite to be imported to the testing tool.
    I would appreciate any help and insight I could receive, and hopefully overcome this roadblock.
    Edited by: user6068303 on Jan 11, 2013 12:33 PM
    Edited by: user6068303 on Jan 11, 2013 12:34 PM

    That's an expected error.
    XMLCDATA takes a string as input, but you're passing it an XMLType instance, therefore an implicit conversion occurs from XMLType to VARCHAR2 which is, as you know, limited to 4000 bytes.
    This indeed gives an error :
    SQL> select xmlelement("OuterElement", xmlcdata(inner_xml))
      2  from (
      3    select xmlelement("InnerElement", rpad(to_clob('X'),8000,'X')) as inner_xml
      4    from dual
      5  ) ;
    ERROR:
    ORA-19011: Character string buffer too small
    no rows selectedThe solution is to serialize the XMLType to CLOB before passing it to XMLCDATA :
    SQL> select xmlelement("OuterElement",
      2           xmlcdata(xmlserialize(document inner_xml))
      3         )
      4  from (
      5    select xmlelement("InnerElement", rpad(to_clob('X'),8000,'X')) as inner_xml
      6    from dual
      7  ) ;
    XMLELEMENT("OUTERELEMENT",XMLCDATA(XMLSERIALIZE(DOCUMENTINNER_XML)))
    <OuterElement><![CDATA[<InnerElement>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX(use getClobVal method if your version doesn't support XMLSerialize)

Maybe you are looking for

  • Cannot update Acrobat Pro to 9.3.2 from 9.3.1

    I am attempting to update Acrobat Pro to 9.3.2 from 9.3.1. Downloading the update, I am met with this: The patch has failed because the application has been modified since it was originally installed (for example, plug-ins may have been disabled).  P

  • Annotations not saved by Acrobat Reader DC

    My annotations are not being saved since the update to AcrobatDC on iOS. I was able to use all of them just before the update. Anyone with the same problem?

  • Edit Graph is Disabled in Disoverer 11g

    Hello, I am trying to create a graph in Discoverer 11g; however the Edit Graph button is disabled. Please help. Regards, Kelly

  • Install Telnet? "pacman -s telnet" doesn't work...

    Trying to search to see if telnet is available for install, but doing "pacman -s telnet" as implied in manpage doesn't work, it just thinks its bad syntax. Also would like to have some information about it before installing (if its possible). As in t

  • Vb type in house production with controls on Max stock level, considering -

    Dear friends, Please think of possible solution to map the follwing scenario, my client having vb tpe scenario for in house mfg product, As the it reaches to re-order level it generates planned order , eg mrp type -vb, reorder point-200 ,min lot size