XMLTable in PL/SQL

I am trying to get data which is in an xmltype table for use in my plsql procedure and keep getting err:
Error(19,41): PLS-00302: component 'OBJECT_VALUE' must be declared
Am I approaching this wrong? It works fine without the into in SQL.
Thanks
declare
v_mc_id number;
v_class_id number;
v_dept VARCHAR2(10);
v_class_num number;
v_section VARCHAR2(10);
v_professor VARCHAR2(100);
v_title VARCHAR2(100);
v_syllabus_hash_key varchar2(512);
BEGIN
-- Get the non-nested items from the XML document
SELECT c.department,c.classNumber,c.section,c.professor,c.title, c.syllabusHashkey
INTO v_dept, v_class_num, v_section, v_professor, v_title, v_syllabus_hash_key
FROM classxml,
xmltable('/class' passing classxml.object_value
columns
department VARCHAR2(10) path 'department',
classNumber number path 'classNumber',
section VARCHAR2(10) path 'section',
professor VARCHAR2(100) path 'professor',
title VARCHAR2(100) path 'classTitle',
syllabusHashKey varchar2(512) path 'syllabusHashKey') c;
end;

The post in the link is very good..However, for starters on XMLTable usage I felt it could be little complex. I found another link that explains the XMLTable Usage with Simple examples. I would like to recommend it for somebody who are trying to get started with XMLTable.
Cheers..

Similar Messages

  • Converting XMLSEQUENCE to XMLTABLE

    So we've gotten part-way into converting all of our code using XMLSEQUENCE to instead use XMLTABLE and everything compiles fine. However, we now realize (a bit late, I realize, and it is documented) that the PASSING clause with XMLTABLE requires a SQL expression.
    All of the XML queries that we use involve the evaluation of a PL/SQL variable - for example, an XMLTYPE variable passed into a procedure. The first example below is using a SQL expression (the return from the XMLTYPE function) in the PASSING clause and this works, but the second example tries to refer to a PL/SQL variable which generates an exception.
    Is XMLTABLE totally off the table if you are working with PL/SQL variables, same as if you attempt to refer to a package variable within a SQL statement?
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    With the Partitioning, Data Mining and Real Application Testing options
    sql>begin
      2      for rec_pkg in (select *
      3                        from xmltable('/data/packages/package'
      4                                      passing xmltype(
      5  '<data>
      6     <packages>
      7      <package upc="00054645172462">
      8      </package>
      9      <package upc="00054645413060">
    10      </package>
    11    </packages>
    12  </data>')
    13                                      columns package_upc varchar2(14) path '@upc')
    14                                     ) loop 
    15      dbms_output.put_line( 'Package UPC: ' || rec_pkg.package_upc);
    16    end loop;
    17  end;
    18  /
    Package UPC: 00054645172462
    Package UPC: 00054645413060
    PL/SQL procedure successfully completed.
    sql>declare
      2   v_xml xmltype := xmltype(
      3  '<data>
      4     <packages>
      5      <package upc="00054645172462">
      6      </package>
      7      <package upc="00054645413060">
      8      </package>
      9    </packages>
    10  </data>');
    11  begin
    12      for rec_pkg in (select *
    13                        from xmltable('/data/packages/package'
    14                                      passing v_xml
    15                                      columns package_upc varchar2(14) path '@upc')
    16                                     ) loop 
    17      dbms_output.put_line( 'Package UPC: ' || rec_pkg.package_upc);
    18    end loop;
    19  end;
    20  /
    declare
    ERROR at line 1:
    ORA-19112: error raised during evaluation:
    ORA-06550: line 1, column 13:
    PLS-00201: identifier 'SYS.DBMS_XQUERYINT' must be declared
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    ORA-06512: at line 12

    Works fine for me:
    declare
        v_xml xmltype := xmltype(
       '<data>
          <packages>
           <package upc="00054645172462">
           </package>
           <package upc="00054645413060">
           </package>
         </packages>
       </data>');
    begin
           for c in (select * from v$version) loop
              dbms_output.put_line(c.banner);
           end loop;
           for rec_pkg in (select *
                             from xmltable('/data/packages/package'
                                           passing v_xml
                                           columns package_upc varchar2(14) path '@upc')
                                          ) loop 
           dbms_output.put_line( 'Package UPC: ' || rec_pkg.package_upc);
         end loop;
    end;
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    PL/SQL Release 10.2.0.3.0 - Production
    CORE     10.2.0.3.0     Production
    TNS for Linux: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    Package UPC: 00054645172462
    Package UPC: 00054645413060
    Statement processed.

  • CLOB Vs XMLTYPE

    Hi Guys,
    In one of my applications , From the front end we are getting XML data and storing the xml data in the col of table which is CLOB type .
    Today one of the application developer told that directly we can store the xml data into the data base.Could any one tell me the difference in storing the data in the clob and xml
    and also what is the advantages of using xml over clob data type.
    Any suggestions will be highly appreciated.
    Thanks,
    Prafulla

    Prafulla wrote:
    Hi Guys,
    In one of my applications , From the front end we are getting XML data and storing the xml data in the col of table which is CLOB type .
    Today one of the application developer told that directly we can store the xml data into the data base.Could any one tell me the difference in storing the data in the clob and xml
    and also what is the advantages of using xml over clob data type.
    Any suggestions will be highly appreciated.
    Thanks,
    PrafullaXMLTYPE is based on the CLOB datatype under the hood. CLOB simply stores a whole stream of characters in one large chunk and you need to use the DBMS_LOB package to pull out any sort of structured information from that CLOB. XMLTYPE on the other hand understands that the content is XML and provides various methods for accessing the data as well as SQL being able to access the XML in a structured manner too.
    For example, if you have some XML in an XMLTYPE, you can use the XMLTABLE keyword in SQL to extract the data from it e.g..
    WITH t as (select XMLTYPE('
    <RECSET>
      <REC>
        <COUNTRY>1</COUNTRY>
        <POINT>1800</POINT>
        <USER_INFO>
          <USER_ID>1</USER_ID>
          <TARGET>28</TARGET>
          <STATE>6</STATE>
          <TASK>12</TASK>
        </USER_INFO>
        <USER_INFO>
          <USER_ID>5</USER_ID>
          <TARGET>19</TARGET>
          <STATE>1</STATE>
          <TASK>90</TASK>
        </USER_INFO>
      </REC>
      <REC>
        <COUNTRY>2</COUNTRY>
        <POINT>2400</POINT>
        <USER_INFO>
          <USER_ID>3</USER_ID>
          <TARGET>14</TARGET>
          <STATE>7</STATE>
          <TASK>5</TASK>
        </USER_INFO>
      </REC>
    </RECSET>') as xml from dual)
    -- END OF TEST DATA
    select x.country, x.point, y.user_id, y.target, y.state, y.task
    from t
        ,XMLTABLE('/RECSET/REC'
                  PASSING t.xml
                  COLUMNS country NUMBER PATH '/REC/COUNTRY'
                         ,point   NUMBER PATH '/REC/POINT'
                         ,user_info XMLTYPE PATH '/REC/*'
                 ) x
        ,XMLTABLE('/USER_INFO'
                  PASSING x.user_info
                  COLUMNS user_id NUMBER PATH '/USER_INFO/USER_ID'
                         ,target  NUMBER PATH '/USER_INFO/TARGET'
                         ,state   NUMBER PATH '/USER_INFO/STATE'
                         ,task    NUMBER PATH '/USER_INFO/TASK'
                 ) y
       COUNTRY      POINT    USER_ID     TARGET      STATE       TASK
             1       1800          1         28          6         12
             1       1800          5         19          1         90
             2       2400          3         14          7          5It uses XQuery expressions to reference the data, so you can reference attributes of the XML elements as well as their values, and you can also use namespaces if those are needed. The above is just a simple example with some nested repeating groups.
    If you tried to extract that data using a CLOB, you'd struggle to do that in SQL easily.

  • XMLTable Problem - works in PL/SQL, why not standalone?

    What is going on here? Why does the plain SQL return this really helpful error?
    <pre>
    SQL> desc CRMAUTOSAVE
    Name Null? Typ
    AS_AUTOSAVEID NOT NULL NUMBER(10)
    AS_IDENT NOT NULL VARCHAR2(250)
    AS_DATA XMLTYPE
    CREATEDATE NOT NULL TIMESTAMP(6)
    CREATOR NOT NULL VARCHAR2(35)
    DELETEFLAG NOT NULL NUMBER(1)
    DELETEDATE TIMESTAMP(6)
    DELETEBY VARCHAR2(35)
    MODIFICATEDATE TIMESTAMP(6)
    MODIFICATOR VARCHAR2(35)
    SQL> select count(*) from CRMAUTOSAVE;
    COUNT(*)
    14
    SQL> select t2.*
    2 from CRMAUTOSAVE
    3 , XMLTable('//Attachment'
    4 passing CRMAUTOSAVE.AS_DATA
    5 columns
    6 ATTID number(10) PATH '/Attachment/@Id'
    7 ) t2;
    ATTID number(10) PATH '/Attachment/@Id'
    FEHLER in Zeile 6:
    ORA-01780: string literal required
    SQL> set serverout on size 100000
    SQL> declare
    2 cursor c is
    3 select t2.*
    4 from CRMAUTOSAVE
    5 , XMLTable('//Attachment'
    6 passing CRMAUTOSAVE.AS_DATA
    7 columns
    8 ATTID number(10) PATH '/Attachment/@Id'
    9 ) t2;
    10
    11 begin
    12 for x in c loop
    13 dbms_output.put_line(x.ATTID);
    14 end loop;
    15 end;
    16 /
    4455225736
    4449873735
    PL/SQL-Prozedur erfolgreich abgeschlossen.
    </pre>

    Further Info:
    <pre>
    SQL*Plus: Release 10.2.0.1.0 - Production on Mo Feb 15 15:29:08 2010
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Kennwort eingeben:
    Verbunden mit:
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
    </pre>
    This is a 10.2.0.3 on SunOS 5.10, Sparc. We connect (apparently) with a 10.2.0.1 windows client.
    It now gets even better, this one works!
    <pre>
    SQL*Plus: Release 10.2.0.4.0 - Production on Mon Feb 15 17:30:52 2010
    Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
    Enter password:
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    With the Partitioning, Oracle Label Security, OLAP, Data Mining Scoring Engine
    and Real Application Testing options
    SQL>
    SQL>
    SQL>
    SQL>
    SQL> select t2.*
    2 from CRMAUTOSAVE
    3 , XMLTable('//Attachment'
    4 passing CRMAUTOSAVE.AS_DATA
    5 columns
    6 ATTID number(10) PATH '/Attachment/@Id'
    7 ) t2;
    ATTID
    4385310450
    4435025574
    </pre>
    This is a 64-bit 10.2.0.4, running on Debian Lenny. Client is a 10.2.0.4 windows.
    I will experiment a bit with different combinations ;)

  • Using XMLTABLE to extract data to use in pl/sql code

    I have an XML message, from which I need to extract the highlighed data and use those values to UPDATE some oracle tables.  I am new to the XMLTABLE function and am having difficulty doing that.  I would really appreciate some help.  The first 2 values I need are CaseTrackingID and CaseDocketId.  I have made those BOLD.
    <GetCaseResponse xmlns="urn:oasis:names:tc:legalxml-courtfiling:wsdl:WebServiceMessagingProfile-Definitions-4.0">
    <GetCaseResponse>
    <CaseResponseMessage xsi:schemaLocation="urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:CaseResponseMessage-4.0 C:\ecf-v4.01-spec-csd01_files\xsd\message\ECF-4.0-CaseResponseMessage.xsd"
    xmlns="urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:CaseResponseMessage-4.0"
    xmlns:j="http://niem.gov/niem/domains/jxdm/4.0"
    xmlns:ecf="urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:CommonTypes-4.0"
    xmlns:nc="http://niem.gov/niem/niem-core/2.0"
    xmlns:s="http://niem.gov/niem/structures/2.0">
    <ecf:SendingMDELocationID>
    <nc:IdentificationID/>
    </ecf:SendingMDELocationID>
    <ecf:SendingMDEProfileCode/>
    <j:CaseCourt/>
    <ecf:Error>
    <ecf:ErrorCode>0</ecf:ErrorCode>
    <ecf:ErrorText>No error</ecf:ErrorText>
    </ecf:Error>
    <court:CourtCase xmlns:court="urn:tyler:ecf:extensions:CourtCase">
    <nc:CaseTitleText></nc:CaseTitleText>
    <nc:CaseCategoryText>7</nc:CaseCategoryText>
    <nc:CaseTrackingID>4812</nc:CaseTrackingID>
    <nc:CaseDocketID>2013-001119</nc:CaseDocketID>
    <court:CaseTypeText>1764</court:CaseTypeText>
    <court:CaseOtherDocketID/>
    <j:CaseAugmentation>
    <j:CaseCourt>
    <nc:OrganizationIdentification>
    <nc:IdentificationID>hcdistrictclerk.com</nc:IdentificationID>
    </nc:OrganizationIdentification>
    <j:CourtName/>
    </j:CaseCourt>
    <j:CaseLineageCase>
    <nc:CaseTrackingID>2889663e-217e-4a99-a8b4-0058f88b4dec</nc:CaseTrackingID>
    </j:CaseLineageCase>
    </j:CaseAugmentation>
    <ecf:CaseAugmentation>
    <ecf:CaseOtherEntityAttorney>
    <nc:RoleOfPersonReference s:ref="Attorney2"/>
    <j:JudicialOfficialBarMembership>
    <j:JudicialOfficialBarIdentification>
    <nc:IdentificationID>123456</nc:IdentificationID>
    <j:IdentificationJurisdictionNCICLISCode>TX</j:IdentificationJurisdictionNCICLISCode>
    </j:JudicialOfficialBarIdentification>
    </j:JudicialOfficialBarMembership>
    <ecf:CaseRepresentedPartyReference s:ref="Party2"/>
    </ecf:CaseOtherEntityAttorney>
    <ecf:CaseOtherEntityAttorney>
    <nc:RoleOfPersonReference s:ref="Attorney1"/>
    <j:JudicialOfficialBarMembership>
    <j:JudicialOfficialBarIdentification>
    <nc:IdentificationID>123456</nc:IdentificationID>
    <j:IdentificationJurisdictionNCICLISCode>TX</j:IdentificationJurisdictionNCICLISCode>
    </j:JudicialOfficialBarIdentification>
    </j:JudicialOfficialBarMembership>
    <ecf:CaseRepresentedPartyReference s:ref="Party1"/>
    </ecf:CaseOtherEntityAttorney>
    <ecf:CaseParticipant>
    <ecf:EntityPerson s:id="Attorney1">
    <nc:PersonName>
    <nc:PersonGivenName>Joe</nc:PersonGivenName>
    <nc:PersonMiddleName></nc:PersonMiddleName>
    <nc:PersonSurName>Singleton</nc:PersonSurName>
    </nc:PersonName>
    <nc:PersonOtherIdentification>
    <nc:IdentificationID>5d12a9cc-1533-4eac-b2c6-3d64a42baa0e</nc:IdentificationID>
    <nc:IdentificationCategoryText>CASEPARTYATTORNEYID</nc:IdentificationCategoryText>
    </nc:PersonOtherIdentification>
    <ecf:PersonAugmentation>
    <nc:ContactInformation>
    <nc:ContactTelephoneNumber>
    <nc:FullTelephoneNumber>
    <nc:TelephoneNumberFullID>210-403-8600</nc:TelephoneNumberFullID>
    </nc:FullTelephoneNumber>
    </nc:ContactTelephoneNumber>
    <nc:ContactEmailID/>
    <nc:ContactMailingAddress>
    <nc:StructuredAddress>
    <nc:LocationStreet>
    <nc:StreetFullText>911 Central PKWY N, Ste 110</nc:StreetFullText>
    </nc:LocationStreet>
    <nc:AddressSecondaryUnitText></nc:AddressSecondaryUnitText>
    <nc:LocationCityName>San Antonio</nc:LocationCityName>
    <nc:LocationStateName>TX</nc:LocationStateName>
    <nc:LocationCountryFIPS10-4Code>US</nc:LocationCountryFIPS10-4Code>
    <nc:LocationPostalCode>78232</nc:LocationPostalCode>
    </nc:StructuredAddress>
    </nc:ContactMailingAddress>
    </nc:ContactInformation>
    </ecf:PersonAugmentation>
    </ecf:EntityPerson>
    <ecf:CaseParticipantRoleCode>ATTY</ecf:CaseParticipantRoleCode>
    </ecf:CaseParticipant>
    <ecf:CaseParticipant>
    <ecf:EntityOrganization s:id="Party1">
    <nc:OrganizationName>Harris County</nc:OrganizationName>
    <nc:OrganizationIdentification>
    <nc:IdentificationID>a174d1a1-0ce2-4a6a-984e-998b890d3e6f</nc:IdentificationID>
    <nc:IdentificationCategoryText>CASEPARTYID</nc:IdentificationCategoryText>
    </nc:OrganizationIdentification>
    <ecf:OrganizationAugmentation>
    <nc:ContactInformation>
    <nc:ContactTelephoneNumber>
    <nc:FullTelephoneNumber>
    <nc:TelephoneNumberFullID>7138443400</nc:TelephoneNumberFullID>
    </nc:FullTelephoneNumber>
    </nc:ContactTelephoneNumber>
    <nc:ContactEmailID/>
    <nc:ContactMailingAddress>
    <nc:StructuredAddress>
    <nc:LocationStreet>
    <nc:StreetFullText>P O BOX 3064</nc:StreetFullText>
    </nc:LocationStreet>
    <nc:AddressSecondaryUnitText></nc:AddressSecondaryUnitText>
    <nc:LocationCityName>Houston</nc:LocationCityName>
    <nc:LocationStateName>TX</nc:LocationStateName>
    <nc:LocationCountryFIPS10-4Code>US</nc:LocationCountryFIPS10-4Code>
    <nc:LocationPostalCode>772533064</nc:LocationPostalCode>
    </nc:StructuredAddress>
    </nc:ContactMailingAddress>
    </nc:ContactInformation>
    </ecf:OrganizationAugmentation>
    </ecf:EntityOrganization>
    <ecf:CaseParticipantRoleCode>1690</ecf:CaseParticipantRoleCode>
    </ecf:CaseParticipant>
    <ecf:CaseParticipant>
    <ecf:EntityPerson s:id="Attorney2">
    <nc:PersonName>
    <nc:PersonGivenName>Joe</nc:PersonGivenName>
    <nc:PersonMiddleName></nc:PersonMiddleName>
    <nc:PersonSurName>Singleton</nc:PersonSurName>
    </nc:PersonName>
    <nc:PersonOtherIdentification>
    <nc:IdentificationID>76ff5e18-9c9a-4957-af4f-64ffa5217cd1</nc:IdentificationID>
    <nc:IdentificationCategoryText>CASEPARTYATTORNEYID</nc:IdentificationCategoryText>
    </nc:PersonOtherIdentification>
    <ecf:PersonAugmentation>
    <nc:ContactInformation>
    <nc:ContactTelephoneNumber>
    <nc:FullTelephoneNumber>
    <nc:TelephoneNumberFullID>210-403-8600</nc:TelephoneNumberFullID>
    </nc:FullTelephoneNumber>
    </nc:ContactTelephoneNumber>
    <nc:ContactEmailID/>
    <nc:ContactMailingAddress>
    <nc:StructuredAddress>
    <nc:LocationStreet>
    <nc:StreetFullText>911 Central PKWY N, Ste 110</nc:StreetFullText>
    </nc:LocationStreet>
    <nc:AddressSecondaryUnitText></nc:AddressSecondaryUnitText>
    <nc:LocationCityName>San Antonio</nc:LocationCityName>
    <nc:LocationStateName>TX</nc:LocationStateName>
    <nc:LocationCountryFIPS10-4Code>US</nc:LocationCountryFIPS10-4Code>
    <nc:LocationPostalCode>78232</nc:LocationPostalCode>
    </nc:StructuredAddress>
    </nc:ContactMailingAddress>
    </nc:ContactInformation>
    </ecf:PersonAugmentation>
    </ecf:EntityPerson>
    <ecf:CaseParticipantRoleCode>ATTY</ecf:CaseParticipantRoleCode>
    </ecf:CaseParticipant>
    <ecf:CaseParticipant>
    <ecf:EntityOrganization s:id="Party2">
    <nc:OrganizationName>City of South Houston</nc:OrganizationName>
    <nc:OrganizationIdentification>
    <nc:IdentificationID>0b04f15a-226d-417f-92e7-8d9088577121</nc:IdentificationID>
    <nc:IdentificationCategoryText>CASEPARTYID</nc:IdentificationCategoryText>
    </nc:OrganizationIdentification>
    <ecf:OrganizationAugmentation>
    <nc:ContactInformation>
    <nc:ContactTelephoneNumber>
    <nc:FullTelephoneNumber>
    <nc:TelephoneNumberFullID>7138443400</nc:TelephoneNumberFullID>
    </nc:FullTelephoneNumber>
    </nc:ContactTelephoneNumber>
    <nc:ContactEmailID/>
    <nc:ContactMailingAddress>
    <nc:StructuredAddress>
    <nc:LocationStreet>
    <nc:StreetFullText>P O BOX 3064</nc:StreetFullText>
    </nc:LocationStreet>
    <nc:AddressSecondaryUnitText></nc:AddressSecondaryUnitText>
    <nc:LocationCityName>Houston</nc:LocationCityName>
    <nc:LocationStateName>TX</nc:LocationStateName>
    <nc:LocationCountryFIPS10-4Code>US</nc:LocationCountryFIPS10-4Code>
    <nc:LocationPostalCode>772533064</nc:LocationPostalCode>
    </nc:StructuredAddress>
    </nc:ContactMailingAddress>
    </nc:ContactInformation>
    </ecf:OrganizationAugmentation>
    </ecf:EntityOrganization>
    <ecf:CaseParticipantRoleCode>1690</ecf:CaseParticipantRoleCode>
    </ecf:CaseParticipant>
    <ecf:CaseParticipant>
    <ecf:EntityPerson s:id="Party3">
    <nc:PersonBirthDate>
    <nc:Date xsi:nil="true"/>
    </nc:PersonBirthDate>
    <nc:PersonName>
    <nc:PersonGivenName>Joseph</nc:PersonGivenName>
    <nc:PersonMiddleName>K.</nc:PersonMiddleName>
    <nc:PersonSurName>Singleton</nc:PersonSurName>
    <nc:PersonNameSuffixText></nc:PersonNameSuffixText>
    </nc:PersonName>
    <nc:PersonOtherIdentification>
    <nc:IdentificationID>c86a92ef-35a4-449f-a729-1bc0c1f769f6</nc:IdentificationID>
    <nc:IdentificationCategoryText>CASEPARTYID</nc:IdentificationCategoryText>
    </nc:PersonOtherIdentification>
    <nc:PersonRaceText/>
    <nc:PersonSexCode xsi:nil="true"/>
    <ecf:PersonAugmentation>
    <nc:ContactInformation>
    <nc:ContactTelephoneNumber>
    <nc:FullTelephoneNumber>
    <nc:TelephoneNumberFullID>7138443400</nc:TelephoneNumberFullID>
    </nc:FullTelephoneNumber>
    </nc:ContactTelephoneNumber>
    <nc:ContactEmailID/>
    <nc:ContactMailingAddress>
    <nc:StructuredAddress>
    <nc:LocationStreet>
    <nc:StreetFullText>P O BOX 3064</nc:StreetFullText>
    </nc:LocationStreet>
    <nc:AddressSecondaryUnitText></nc:AddressSecondaryUnitText>
    <nc:LocationCityName>Houston</nc:LocationCityName>
    <nc:LocationStateName>TX</nc:LocationStateName>
    <nc:LocationCountryFIPS10-4Code>US</nc:LocationCountryFIPS10-4Code>
    <nc:LocationPostalCode>772533064</nc:LocationPostalCode>
    </nc:StructuredAddress>
    </nc:ContactMailingAddress>
    </nc:ContactInformation>
    </ecf:PersonAugmentation>
    </ecf:EntityPerson>
    <ecf:CaseParticipantRoleCode>1679</ecf:CaseParticipantRoleCode>
    </ecf:CaseParticipant>
    <ecf:CaseParticipant>
    <ecf:EntityPerson s:id="Party4">
    <nc:PersonBirthDate>
    <nc:Date xsi:nil="true"/>
    </nc:PersonBirthDate>
    <nc:PersonName>
    <nc:PersonGivenName>Raul</nc:PersonGivenName>
    <nc:PersonMiddleName></nc:PersonMiddleName>
    <nc:PersonSurName>Garza</nc:PersonSurName>
    <nc:PersonNameSuffixText></nc:PersonNameSuffixText>
    </nc:PersonName>
    <nc:PersonOtherIdentification>
    <nc:IdentificationID>15440071-302d-44f1-82e4-3fc930532049</nc:IdentificationID>
    <nc:IdentificationCategoryText>CASEPARTYID</nc:IdentificationCategoryText>
    </nc:PersonOtherIdentification>
    <nc:PersonRaceText/>
    <nc:PersonSexCode xsi:nil="true"/>
    <ecf:PersonAugmentation>
    <nc:ContactInformation>
    <nc:ContactTelephoneNumber>
    <nc:FullTelephoneNumber>
    <nc:TelephoneNumberFullID></nc:TelephoneNumberFullID>
    </nc:FullTelephoneNumber>
    </nc:ContactTelephoneNumber>
    <nc:ContactEmailID/>
    <nc:ContactMailingAddress>
    <nc:StructuredAddress>
    <nc:LocationStreet>
    <nc:StreetFullText>222 South Fork</nc:StreetFullText>
    </nc:LocationStreet>
    <nc:AddressSecondaryUnitText></nc:AddressSecondaryUnitText>
    <nc:LocationCityName>Houston</nc:LocationCityName>
    <nc:LocationStateName>TX</nc:LocationStateName>
    <nc:LocationCountryFIPS10-4Code>US</nc:LocationCountryFIPS10-4Code>
    <nc:LocationPostalCode>77148</nc:LocationPostalCode>
    </nc:StructuredAddress>
    </nc:ContactMailingAddress>
    </nc:ContactInformation>
    </ecf:PersonAugmentation>
    </ecf:EntityPerson>
    <ecf:CaseParticipantRoleCode>1666</ecf:CaseParticipantRoleCode>
    </ecf:CaseParticipant>
    <ecf:CaseParticipant>
    <ecf:EntityPerson s:id="Party5">
    <nc:PersonBirthDate>
    <nc:Date xsi:nil="true"/>
    </nc:PersonBirthDate>
    <nc:PersonName>
    <nc:PersonGivenName>Sandra</nc:PersonGivenName>
    <nc:PersonMiddleName>A.</nc:PersonMiddleName>
    <nc:PersonSurName>Garza</nc:PersonSurName>
    <nc:PersonNameSuffixText></nc:PersonNameSuffixText>
    </nc:PersonName>
    <nc:PersonOtherIdentification>
    <nc:IdentificationID>c346477d-90eb-4323-b082-7cc8edc6d143</nc:IdentificationID>
    <nc:IdentificationCategoryText>CASEPARTYID</nc:IdentificationCategoryText>
    </nc:PersonOtherIdentification>
    <nc:PersonRaceText/>
    <nc:PersonSexCode xsi:nil="true"/>
    <ecf:PersonAugmentation>
    <nc:ContactInformation>
    <nc:ContactTelephoneNumber>
    <nc:FullTelephoneNumber>
    <nc:TelephoneNumberFullID></nc:TelephoneNumberFullID>
    </nc:FullTelephoneNumber>
    </nc:ContactTelephoneNumber>
    <nc:ContactEmailID/>
    <nc:ContactMailingAddress>
    <nc:StructuredAddress>
    <nc:LocationStreet>
    <nc:StreetFullText>L J Garage</nc:StreetFullText>
    </nc:LocationStreet>
    <nc:AddressSecondaryUnitText>902 Arkansas St</nc:AddressSecondaryUnitText>
    <nc:LocationCityName>South Houston</nc:LocationCityName>
    <nc:LocationStateName>TX</nc:LocationStateName>
    <nc:LocationCountryFIPS10-4Code>US</nc:LocationCountryFIPS10-4Code>
    <nc:LocationPostalCode>775874916</nc:LocationPostalCode>
    </nc:StructuredAddress>
    </nc:ContactMailingAddress>
    </nc:ContactInformation>
    </ecf:PersonAugmentation>
    </ecf:EntityPerson>
    <ecf:CaseParticipantRoleCode>1666</ecf:CaseParticipantRoleCode>
    </ecf:CaseParticipant>
    </ecf:CaseAugmentation>
    </court:CourtCase>
    </CaseResponseMessage>
    </GetCaseResponse>
    </GetCaseResponse>

    Hi,
    I have some characters like below in oracle production database.
    COMPAÑÍA
    AGUARAGÜE
    I am taking the data from prod and loading the same in staging as it is.
    We use some EAI tools and generate the flat files and load those files into another oracle database. We get failed for those records which has special charaters like above.
    Both are oracle databases and one supports these characters and other doesnt't.
    Do we need to make any configuration changes at the database level?
    If any one worked on this scenario, pls help me out.
    Thanks,
    Vijay

  • Issue with SQL for the XMLTABLE

    Hi ,
    Here is what I want to Achieve :
    This is my XSD :
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns="http://my-company.com/namespace" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://my-company.com/namespace" elementFormDefault="qualified" attributeFormDefault="unqualified">
         <xs:element name="NOTE" type="NOTEType">
              <xs:annotation>
                   <xs:documentation>Root Element</xs:documentation>
              </xs:annotation>
         </xs:element>
         <xs:complexType name="NOTEType">
              <xs:sequence>
                   <xs:element name="TO" type="SENDERTYPE"/>
                   <xs:element name="FROM" type="RECEIVERTYPE"/>
                   <xs:element name="HEADING" type="HEADINGTYPE"/>
                   <xs:element name="BODY" type="xs:string"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="SENDERTYPE">
              <xs:sequence>
                   <xs:element name="COMPANY" type="xs:string"/>
                   <xs:element name="INDIVIDUAL" type="xs:string" maxOccurs="unbounded"/>
                   <xs:element name="ORGANIZATION" type="xs:string"/>
                   <xs:element name="DEPARTMENT" type="xs:string" maxOccurs="unbounded"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="RECEIVERTYPE">
              <xs:sequence>
                   <xs:element name="COMPANY" type="xs:string"/>
                   <xs:element name="INDIVIDUAL" type="xs:string" maxOccurs="unbounded"/>
                   <xs:element name="ORGANIZATION" type="xs:string"/>
                   <xs:element name="DEPARTMENT" type="xs:string" maxOccurs="unbounded"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="HEADINGTYPE">
              <xs:sequence>
                   <xs:element name="SINGLELINE">
                        <xs:simpleType>
                             <xs:restriction base="xs:string">
                                  <xs:maxLength value="200"/>
                             </xs:restriction>
                        </xs:simpleType>
                   </xs:element>
                   <xs:element name="MULTILINE" type="xs:string"/>
              </xs:sequence>
         </xs:complexType>
    </xs:schema>
    This is my XML Document : (I Have 3 ,more similar Similar XML Files in the NOTES table)
    <?xml version="1.0" encoding="UTF-8"?>
    <NOTE xmlns="http://my-company.com/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://my-company.com/namespace file:///C:/Documents%20and%20Settings/saoa/Desktop/MY%20WORK/XML/NOTE.xsd">
         <TO>
              <COMPANY>United Guaranty</COMPANY>
              <INDIVIDUAL/>
              <ORGANIZATION/>
              <DEPARTMENT/>
         </TO>
         <FROM>
              <COMPANY/>
              <INDIVIDUAL>Aniket Sao</INDIVIDUAL>
              <INDIVIDUAL>Monit Sao</INDIVIDUAL>
              <INDIVIDUAL>Yeshwant Sao</INDIVIDUAL>
              <INDIVIDUAL>Dashrath Sao</INDIVIDUAL>
              <ORGANIZATION/>
              <DEPARTMENT/>
         </FROM>
         <HEADING>
              <SINGLELINE>Just Testing XML</SINGLELINE>
              <MULTILINE/>
         </HEADING>
         <BODY>This is just to test of the XML works fine</BODY>
    </NOTE>
    The Output which I'm trying to get is
    NOTESID -     TOCOMPANY -     TOINDIVIDUAL -     TOORGANIZATION -     TODEPARTMENT-     FROMCOMPANY-     FROMINDIVIDUAL-     FROMORGANIZATION-     FROMDEPARTMENT-     SINGLEHEADING-     MULTIHEADING-     BODY-
    1-     United Guaranty-     NULL-     NULL-     NULL-     NULL-     Aniket Sao-     NULL-     NULL-     Just Testing XML-     NULL-     This is just to test of the XML works fine-
    2-     United Guaranty-     NULL-     NULL-     NULL-     NULL-     Monit Sao-     NULL-     NULL-     Just Testing XML-     NULL-     This is just to test of the XML works fine-
    3-     United Guaranty-     NULL-     NULL-     NULL-     NULL-     Yeshwant Sao-     NULL-     NULL-     Just Testing XML-     NULL-     This is just to test of the XML works fine
    4-     United Guaranty-     NULL-     NULL-     NULL-     NULL-     Dashrath Sao-     NULL-     NULL-     Just Testing XML-     NULL-     This is just to test of the XML works fine
    Here is the Query I Fire :
    SELECT
    NOTES2."TO",
    NOTES2."FROM",
    NOTES2."HEADING",
    NOTES2."BODY"
    FROM NOTES,
    XMLTABLE('/NOTE'
    PASSING NOTES.NOTESXMLCOL
    COLUMNS
    "TO" varchar2(50) PATH '/NOTE/TO',
    "FROM" varchar2(50) PATH '/NOTE/FROM',
    "HEADING" varchar2(50) PATH '/NOTE/HEADING',
    "BODY" varchar2(300) PATH '/NOTE/BODY')
    NOTES2;
    This is the Result I get
    TO FROM HEADING BODY
    United Guaranty      Aniket SaoMonit SaoYeshwant SaoDashrath Sao     Just Testing XML     This is just to test of the XML works fine
    I want to split up the Multiple occurance of the node into different rows. how to do that ?
    I Event tried this ;
    SELECT NOTESID NOTES,
    NOTES2."TOCOMPANY",
    NOTES2."TOINDIVIDUAL",
    NOTES2."TOORGANIZATION",
    NOTES2."TODEPARTMENT",
    NOTES2."FROMCOMPANY",
    NOTES2."FROMINDIVIDUAL",
    NOTES2."FROMORGANIZATION",
    NOTES2."FROMDEPARTMENT",
    NOTES2."SINGLEHEADING",
    NOTES2."MULTIHEADING",
    NOTES2."BODY"
    FROM NOTES,
    XMLTABLE('/NOTE'
    PASSING NOTES.NOTESXMLCOL
    COLUMNS
    "TOCOMPANY" varchar2(50) PATH '/NOTE/TO/COMPANY',
    "TOINDIVIDUAL" varchar2(50) PATH '/NOTE/TO/INDIVIDUAL',
    "TOORGANIZATION" varchar2(50) PATH '/NOTE/TO/ORGANIZATION',
    "TODEPARTMENT" varchar2(50) PATH '/NOTE/TO/DEPARTMENT',
    "FROMCOMPANY" varchar2(50) PATH '/NOTE/FROM/COMPANY',
    "FROMINDIVIDUAL" varchar2(50) PATH '/NOTE/FROM/INDIVIDUAL',
    "FROMORGANIZATION" varchar2(50) PATH '/NOTE/FROM/ORGANIZATION',
    "FROMDEPARTMENT" varchar2(50) PATH '/NOTE/FROM/DEPARTMENT',
    "SINGLEHEADING" varchar2(50) PATH '/NOTE/HEADING/SINGLELINE',
    "MULTIHEADING" varchar2(50) PATH '/NOTE/HEADING/MULTILINE',
    "BODY" varchar2(300) PATH '/NOTE/BODY')
    NOTES2;
    I Get
    ORA-19279: XPTY0004 - XQuery dynamic type mismatch: expected singleton sequence - got multi-item sequence
    19279. 00000 - "XQuery dynamic type mismatch: expected singleton sequence - got multi-item sequence"
    *Cause:    The XQuery sequence passed in had more than one item.
    *Action:   Correct the XQuery expression to return a single item sequence.
    Please help.
    Thanks,
    Aniket

    Hi,
    Note for next time : Oracle XML-related questions are best posted in the {forum:id=34} forum.
    The exact database version would be appreciated too.
    Repeating elements are typically handled by adding a nested XMLTable to shred them into relational rows :
    SELECT x1.to_company
         , x1.to_individual
         , x1.to_organization
         , x1.to_department
         , x1.from_company
         , x2.from_individual
         , x1.from_organization
         , x1.from_department
         , x1.single_heading
         , x1.multi_heading
         , x1.body
    FROM notes t
       , XMLTable(
           XMLNamespaces(default 'http://my-company.com/namespace')
         , '/NOTE'
           passing t.notesxmlcol
           columns
             to_company        varchar2(50)  PATH 'TO/COMPANY'
           , to_individual     varchar2(50)  PATH 'TO/INDIVIDUAL'
           , to_organization   varchar2(50)  PATH 'TO/ORGANIZATION'
           , to_department     varchar2(50)  PATH 'TO/DEPARTMENT'
           , from_company      varchar2(50)  PATH 'FROM/COMPANY'
           , from_individuals  xmltype       PATH 'FROM/INDIVIDUAL'
           , from_organization varchar2(50)  PATH 'FROM/ORGANIZATION'
           , from_department   varchar2(50)  PATH 'FROM/DEPARTMENT'
           , single_heading    varchar2(50)  PATH 'HEADING/SINGLELINE'
           , multi_heading     varchar2(50)  PATH 'HEADING/MULTILINE'
           , body              varchar2(300) PATH 'BODY'
         ) x1
       , XMLTable(
           XMLNamespaces(default 'http://my-company.com/namespace')
         , '/INDIVIDUAL'
           passing x1.from_individuals
           columns
             from_individual   varchar2(50)  PATH 'text()'
         ) x2
    ;I guess it's probably not your actual schema, but having unwrapped unbounded elements in the middle of the document doesn't make it a good candidate for a relational output.
    For example, what output would you require if, at the same time, there are multiple occurrences of FROM/DEPARTMENT, FROM/INDIVIDUAL, TO/DEPARTMENT and TO/INDIVIDUAL?

  • Update the passed XML in a PL/SQL procedure and then use DBMS_XMLSAVE

    hi folks,
    This is a great forum and most of you guys were awesome in replying to complex queries........
    I have a small issue, I am trying to do a bulk insert from my application by constructing an XML result set and pass that XML to the SP as a CLOB and using DBMS_XMLSAVE package to insert it to the oracle table. It works like a charm for me when this is as straight forward as this. But when my requirement is, I need to generate sequence numbers for a particular column (Primary key column), while for other columns I pass values from the UI (as a XML object which my SP accepts as a CLOB), i am at a loss for solution to achieve this. It would mean, that I have to generate the sequence numbers for each row and then update this value to the passed XML clob. Any indicators on how to achieve this?
    I found this solution at one of the thread which might most probably help me,
    declare
    2 l_cnt number;
    3 begin
    4 select count(*) into l_cnt from books,xmltable('/Books/Book' passing object_value);
    5 for i in 1..l_cnt loop
    6 update books set object_value =
    7 updatexml(object_value,'/Books/Book['||i||']/BookID', xmlelement("BookID",sequence_bookid.nextval))
    8 where existsnode(object_value,'/Books/Book['||i||']')=1;
    9 end loop;
    10 end;
    11 /
    But here, they are trying to update a XMLTable book, but in my case the XML is a clob object and not a XML table. Will this solution work for my case as well? Please provide any pointers to me... Thanks...

    First if your version of Oracle has DBMS_XMLSTORE, use that instead.
    Reason: {thread:id=876376} (See Marco's response).
    It is possible you could run into issues, but you should start with DBMS_XMLSTORE.
    Since you will have the XML in the SP, treat the data as an XMLType instead of a CLOB for as long as you can since you need to do UpdateXML on it.
    For your sample PL/SQL code, lines 4-5 are replaced with the WHILE loop shown in Method 2 at
    {message:id=3610259}.
    The UPDATE would be replaced with the following pseudocode
    SELECT UPDATEXML(<l_xmltype_variable>, ...)
    INTO <l_xmltype_variable>
    FROM dual;
    Once your loop is done, l_xmltype_variable would contain your updated XML and then you can use that XMLType directly on the call to DBMS_XMLSTORE or convert it back to a clob via
    l_clob_variable := l_xmltype_variable.getClobVal();

  • Load XML File into temporary tables using sql loader

    Hi All,
    I have an XML file as below. I need to insert the contents into a temporary staging table using sql loader. Please advice how I need to do that.
    For example Portfolios should go into a seperate table, and all the tags inside it should be populated in the columns of the table.
    Family should go into a seperate table and all the tags inside it should be populated in the columns of the table.
    Similarly offer, Products etc.
    - <ABSProductCatalog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    - <ProductSalesHierachy>
    - <Portfolios>
    - <Portfolio productCode="P1">
      <Attribute name="CatalogProductName" value="Access" />
      <Attribute name="Status" value="Active" />
      </Portfolio>
    - <Portfolio productCode="P2">
      <Attribute name="CatalogProductName" value="Data" />
      <Attribute name="Status" value="Active" />
      </Portfolio>
    - <Portfolio productCode="P3">
      <Attribute name="CatalogProductName" value="Voice" />
      <Attribute name="Status" value="Active" />
      </Portfolio>
    - <Portfolio productCode="P4">
      <Attribute name="CatalogProductName" value="Wireless" />
      <Attribute name="Status" value="Active" />
      </Portfolio>
      </Portfolios>
    - <Families>
    - <Family productCode="F1">
      <Attribute name="CatalogProductName" value="Internet Access Services" />
      <Attribute name="Status" value="Active" />
    - <ParentHierarchy>
      <Item productCode="P1" modelType="Portfolio" />
      </ParentHierarchy>
      </Family>
    - <Family productCode="F2">
      <Attribute name="CatalogProductName" value="Local Access Services" />
      <Attribute name="Status" value="Active" />
    - <ParentHierarchy>
      <Item productCode="P2" modelType="Portfolio" />
      </ParentHierarchy>
      </Family>
      </Families>
    - <SubFamilies>
    - <SubFamily productCode="SF1">
      <Attribute name="CatalogProductName" value="Business Internet service" />
      <Attribute name="Status" value="Active" />
    - <ParentHierarchy>
      <Item productCode="F1" modelType="Family" />
      </ParentHierarchy>
      </SubFamily>
      </SubFamilies>
    - <ProductRefs>
    - <ProductRef productCode="WSP1" modelType="Wireline Sales Product">
      <ActiveFlag>Y</ActiveFlag>
    - <ProductHierarchy>
      <SalesHierarchy family="F1" subFamily="SF1" portfolio="P1" primary="Y" />
      <SalesHierarchy family="F2" portfolio="P2" primary="N" />
      <FinancialHierarchy quotaBucket="Voice" strategicProdCategory="Local Voice" />
      </ProductHierarchy>
      </ProductRef>
    - <ProductRef productCode="MSP2" modelType="Handset">
      <ActiveFlag>Y</ActiveFlag>
    - <ProductHierarchy>
      <SalesHierarchy portfolio="P4" primary="Y" />
      </ProductHierarchy>
      </ProductRef>
      </ProductRefs>
      </ProductSalesHierachy>
    - <Offers>
    - <Offer productCode="ABN">
      <OfferName>ABN</OfferName>
      <OfferDescription>ABN Description</OfferDescription>
    - <Segments>
      <Segment>SCG</Segment>
      <Segment>PCG</Segment>
      </Segments>
      <OfferUpdateDate>2009-11-20</OfferUpdateDate>
      <ActiveFlag>Y</ActiveFlag>
      </Offer>
    - <Offer productCode="OneNet">
      <OfferName>OneNet</OfferName>
      <OfferDescription>OneNet Description</OfferDescription>
    - <Segments>
      <Segment>SCG</Segment>
      <Segment>PCG</Segment>
      <Segment>PCG2</Segment>
      </Segments>
      <OfferUpdateDate>2009-11-20</OfferUpdateDate>
      <ActiveFlag>Y</ActiveFlag>
      </Offer>
      </Offers>
    - <Products>
    - <Product productCode="WSP1" modelType="Wireline Sales Product">
      <ProductName>AT&T High Speed Internet</ProductName>
      <ProductDescription>High Speed Internet</ProductDescription>
      <LegacyCoProdIndicator>SBC</LegacyCoProdIndicator>
      <RevenueCBLCode>1234B</RevenueCBLCode>
      <VolumeCBLCode>4567A</VolumeCBLCode>
      <SAARTServiceIDCode>S1234</SAARTServiceIDCode>
      <MarginPercentRequired>Y</MarginPercentRequired>
      <PercentIntl>%234</PercentIntl>
      <UOM>Each</UOM>
      <PriceType>OneTime</PriceType>
      <ProductStatus>Active</ProductStatus>
      <Compensable>Y</Compensable>
      <Jurisdiction>Everywhere</Jurisdiction>
      <ActiveFlag>Y</ActiveFlag>
    - <Availabilities>
      <Availability>SE</Availability>
      <Availability>E</Availability>
      </Availabilities>
    - <Segments>
      <Segment>SCG</Segment>
      <Segment>PCG</Segment>
      </Segments>
      <VDIndicator>Voice</VDIndicator>
      <PSOCCode>PSOC 1</PSOCCode>
      <USBilled>Y</USBilled>
      <MOWBilled>N</MOWBilled>
      <ProductStartDate>2009-11-20</ProductStartDate>
      <ProductUpdateDate>2009-11-20</ProductUpdateDate>
      <ProductEndDate>2010-11-20</ProductEndDate>
    - <AliasNames>
      <AliasName>AT&T HSI</AliasName>
      <AliasName>AT&T Fast Internet</AliasName>
      </AliasNames>
    - <OfferTypes>
      <OfferType productCode="ABN" endDate="2009-11-20" />
      <OfferType productCode="OneNet" />
      </OfferTypes>
    - <DynamicAttributes>
    - <DynamicAttribute dataType="String" defaultValue="2.5 Mbps" name="Speed">
      <AttrValue>1.5 Mbps</AttrValue>
      <AttrValue>2.5 Mbps</AttrValue>
      <AttrValue>3.5 Mbps</AttrValue>
      </DynamicAttribute>
    - <DynamicAttribute dataType="String" name="TransportType">
      <AttrValue>T1</AttrValue>
      </DynamicAttribute>
      </DynamicAttributes>
      </Product>
    - <Product productCode="MSP2" modelType="Handset">
      <ProductName>Blackberry Bold</ProductName>
      <ProductDescription>Blackberry Bold Phone</ProductDescription>
      <LegacyCoProdIndicator />
      <RevenueCBLCode />
      <VolumeCBLCode />
      <SAARTServiceIDCode />
      <MarginPercentRequired />
      <PercentIntl />
      <UOM>Each</UOM>
      <PriceType />
      <ProductStatus>Active</ProductStatus>
      <Compensable />
      <Jurisdiction />
      <ActiveFlag>Y</ActiveFlag>
    - <Availabilities>
      <Availability />
      </Availabilities>
    - <Segments>
      <Segment>SCG</Segment>
      <Segment>PCG</Segment>
      </Segments>
      <VDIndicator>Voice</VDIndicator>
      <PSOCCode />
      <USBilled />
      <MOWBilled />
      <ProductStartDate>2009-11-20</ProductStartDate>
      <ProductUpdateDate>2009-11-20</ProductUpdateDate>
    - <AliasNames>
      <AliasName />
      </AliasNames>
    - <OfferTypes>
      <OfferType productCode="ABN" />
      </OfferTypes>
    - <DynamicAttributes>
    - <DynamicAttribute dataType="String" name="StlmntContractType">
      <AttrValue />
      </DynamicAttribute>
    - <DynamicAttribute dataType="String" name="BMG 2 year price">
      <AttrValue>20</AttrValue>
      </DynamicAttribute>
    - <DynamicAttribute dataType="String" name="MSRP">
      <AttrValue>40</AttrValue>
      </DynamicAttribute>
    - <DynamicAttribute dataType="String" name="BMGAvailableType">
      <AttrValue />
      </DynamicAttribute>
    - <DynamicAttribute dataType="String" name="ProductId">
      <AttrValue>123456</AttrValue>
      </DynamicAttribute>
    - <DynamicAttribute dataType="String" name="modelSource">
      <AttrValue>product</AttrValue>
      </DynamicAttribute>
      </DynamicAttributes>
      </Product>
      </Products>
      <CatalogChanged>Y</CatalogChanged>
      </ABSProductCatalog>

    Two options that come to mind. Others exist.
    #1 - {thread:id=474031}, which is basically storing the XML in an Object Relational structure for parsing
    #2 - Dump the XML into either an XMLType based table or column and use SQL (with XMLTable) to create a view that parses the data. This would be the same as the view shown in the above post.
    Don't use sql*loader to parse the XML. I was trying to find a post from mdrake about that but couldn't. In short, sql*loader was not build as an XML parser so don't try to use it that way.

  • Summary of  a table in SQL

    I need a query to print summary of table in a single query without using PLSQL..
    table list
    with t as
    select 1 table_number , 't1' table_name from dual
    union all
    select 2 table_number , 't2' table_name from dual
    union all
    select 2 table_number , 't3' table_name from dual
    select * from t;
    Table1
    with t1 as
    select 'US' country_code  , 'SYSTEM1' source, 1 emp_num , 'Not Processed' status from dual
    union all
    select 'India' country_code  , 'SYSTEM1' source, 2 emp_num , 'Valid' status from dual
    union all
    select 'India' country_code  , 'SYSTEM2' source, 3 emp_num , 'Error' status from dual
    union all
    select 'India' country_code  , 'SYSTEM2' source, 4 emp_num , 'Valid' status from dual
    select * from t1;
    i need a query where with input parameter as table_number...
    for eg 1 .. i want the output should be grouped by table_name ,country_code and  source
    output like
    table_name country_code source total_records valid_records error_records not_processed_records valid_records_percentage
    t1         India       SYSTEM1  1             1             0              0                     100
    t1         India       SYSTEM2  2             1             1              0                     50
    t1         US          SYSTEM1  1             0             0              1                     0
    Total                                     4             2             1              1                     50                    
    and i need total for these in last record

    Are you looking to get the table name dynamically? In that case try this.
    SQL> select * from t;
    TABLE_NUMBER TABLE_NAME
               1 t1
               2 t2
               2 t3
    SQL> select * from t1;
    COUNTRY_CODE  SOURCE     EMP_NUM STATUS
    US            SYSTEM1          1 Not Processed
    India         SYSTEM1          2 Valid
    India         SYSTEM2          3 Error
    India         SYSTEM2          4 Valid
    SQL> select case when grouping_id(table_name)
      2                 + grouping_id(country_code)
      3                 + grouping_id(source_) = 0 then table_name
      4              else 'Total'
      5         end table_name
      6       , country_code
      7       , source_
      8       , count(*) total_record
      9       , count(decode(status, 'Not Processed', 1)) not_processed
    10       , count(decode(status, 'Valid', 1)) valid
    11       , count(decode(status, 'Error', 1)) error_
    12    from (
    13            select t.table_name
    14                 , t1.country_code
    15                 , t1.source_
    16                 , t1.emp_num
    17                 , t1.status
    18              from (
    19                      select table_name
    20                           , dbms_xmlgen.getxmltype('select * from ' || table_name) xml_output
    21                        from t
    22                       where table_number = 1
    23                   ) t
    24                 , xmltable
    25                   (
    26                      '/ROWSET/ROW' passing t.xml_output
    27                      columns
    28                      country_code varchar2(100) path 'COUNTRY_CODE',
    29                      source_      varchar2(100) path 'SOURCE',
    30                      emp_num      number        path 'EMP_NUM',
    31                      status       varchar2(100) path 'STATUS'
    32                   ) t1
    33         )
    34   group
    35      by rollup
    36         (
    37            table_name
    38          , country_code
    39          , source_
    40         )
    41  having grouping_id(table_name)
    42       + grouping_id(country_code)
    43       + grouping_id(source_) in (0, 3);
    TABLE_NAME  COUNTRY_CODE  SOURCE_    TOTAL_RECORD NOT_PROCESSED      VALID     ERROR_
    t1          US            SYSTEM1               1             1          0          0
    t1          India         SYSTEM1               1             0          1          0
    t1          India         SYSTEM2               2             0          1          1
    Total                                           4             1          2          1
    SQL>
    For this to work all the table that are passed must have the same structure. But then comes the question why do you have different table with same structure

  • Problem with XMLTABLE and LEFT OUTER JOIN

    Hi all.
    I have one problem with XMLTABLE and LEFT OUTER JOIN, in 11g it returns correct result but in 10g it doesn't, it is trated as INNER JOIN.
    SELECT * FROM v$version;
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    PL/SQL Release 11.2.0.1.0 - Production
    "CORE     11.2.0.1.0     Production"
    TNS for Linux: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    --test for 11g
    CREATE TABLE XML_TEST(
         ID NUMBER(2,0),
         XML XMLTYPE
    INSERT INTO XML_TEST
    VALUES
         1,
         XMLTYPE
              <msg>
                   <data>
                        <fields>
                             <id>g1</id>
                             <dat>data1</dat>
                        </fields>
                   </data>
              </msg>
    INSERT INTO XML_TEST
    VALUES
         2,
         XMLTYPE
              <msg>
                   <data>
                        <fields>
                             <id>g2</id>
                             <dat>data2</dat>
                        </fields>
                   </data>
              </msg>
    INSERT INTO XML_TEST
    VALUES
         3,
         XMLTYPE
              <msg>
                   <data>
                        <fields>
                             <id>g3</id>
                             <dat>data3</dat>
                        </fields>
                        <fields>
                             <id>g4</id>
                             <dat>data4</dat>
                        </fields>
                        <fields>
                             <dat>data5</dat>
                        </fields>
                   </data>
              </msg>
    SELECT
         t.id,
         x.dat,
         y.seqno,
         y.id_real
    FROM
         xml_test t,
         XMLTABLE
              '/msg/data/fields'
              passing t.xml
              columns
                   dat VARCHAR2(10) path 'dat',
                   id XMLTYPE path 'id'
         )x LEFT OUTER JOIN
         XMLTABLE
              'id'
              passing x.id
              columns
                   seqno FOR ORDINALITY,
                   id_real VARCHAR2(30) PATH '.'
         )y ON 1=1
    ID     DAT     SEQNO     ID_REAL
    1     data1     1     g1
    2     data2     1     g2
    3     data3     1     g3
    3     data4     1     g4
    3     data5          Here's everything fine, now the problem:
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bi
    PL/SQL Release 10.2.0.1.0 - Production
    "CORE     10.2.0.1.0     Production"
    TNS for HPUX: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    --exactly the same environment as 11g (tables and rows)
    SELECT
         t.id,
         x.dat,
         y.seqno,
         y.id_real
    FROM
         xml_test t,
         XMLTABLE
              '/msg/data/fields'
              passing t.xml
              columns
                   dat VARCHAR2(10) path 'dat',
                   id XMLTYPE path 'id'
         )x LEFT OUTER JOIN
         XMLTABLE
              'id'
              passing x.id
              columns
                   seqno FOR ORDINALITY,
                   id_real VARCHAR2(30) PATH '.'
         )y ON 1=1
    ID     DAT     SEQNO     ID_REAL
    1     data1     1     g1
    2     data2     1     g2
    3     data3     1     g3
    3     data4     1     g4As you can see in 10g I don't have the last row, it seems that Oracle 10g doesn't recognize the LEFT OUTER JOIN.
    Is this a bug?, Metalink says that sometimes we can have an ORA-0600 but in this case there is no error returned, just incorrect results.
    Please help.
    Regards.

    Hi A_Non.
    Thanks a lot, I tried with this:
    SELECT
         t.id,
         x.dat,
         y.seqno,
         y.id_real
    FROM
         xml_test t,
         XMLTABLE
              '/msg/data/fields'
              passing t.xml
              columns
                   dat VARCHAR2(10) path 'dat',
                   id XMLTYPE path 'id'
         )x,
         XMLTABLE
              'id'
              passing x.id
              columns
                   seqno FOR ORDINALITY,
                   id_real VARCHAR2(30) PATH '.'
         )(+) y ;And is giving me the complete output.
    Thanks again.
    Regards.

  • Performance problems with XMLTABLE and XMLQUERY involving relational data

    Hello-
    Is anyone out there using XMLTABLE or XMLQUERY with more than a toy set of data? I am running into serious performance problems tyring to do basic things such as:
    * Combine records in 10 relational tables into a single table of XMLTYPE records using XMLTABLE. This hangs indefinitely for any more than 800 records. Oracle has confirmed that this is a problem and is working on a fix.
    * Combine a single XMLTYPE record with several relational code tables into a single XMLTYPE record using XMLQUERY and ora:view() to insert code descriptions after each code. Performance is 10 seconds for 10 records (terrible) passing a batch of records , or 160 seconds for one record (unacceptable!). How can it take 10 times longer to process 1/10th the number of records? Ironically, the query plan says it will do a full table scan of records for the batch, but an index access for the one record passed to the XMLQUERY.
    I am rapidly losing faith in XML DB, and desparately need some hints on how to work around these performance problems, or at least some assurance that others have been able to get this thing to perform.

    <Note>Long post, sorry.</Note>
    First, thanks for the responses above. I'm impressed with the quality of thought put into them. (Do the forum rules allow me to offer rewards? :) One suggestion in particular made a big performance improvement, and I’m encouraged to hear of good performance in pure XML situations. Unfortunately, I think there is a real performance challenge in two use cases that are pertinent to the XML+relational subject of this post and probably increasingly common as XML DB usage increases:
    •     Converting legacy tabular data into XML records; and
    •     Performing code table lookups for coded values in XML records.
    There are three things I want to accomplish with this post:
    •     Clarify what we are trying to accomplish, which might expose completely different approaches than I have tried
    •     Let you know what I tried so far and the rationale for my approach to help expose flaws in my thinking and share what I have learned
    •     Highlight remaining performance issues in hopes that we can solve them
    What we are trying to accomplish:
    •     Receive a monthly feed of 10,000 XML records (batched together in text files), each containing information about an employee, including elements that repeat for every year of service. We may need to process an annual feed of 1,000,000 XML records in the future.
    •     Receive a one-time feed of 500,000 employee records stored in about 10 relational tables, with a maximum join depth of 2 or 3. This is inherently a relational-to-XML process. One record/second is minimally acceptable, but 10 records/sec would be better.
    •     Consolidate a few records (from different providers) for each employee into a single record. Given the data volume, we need to achieve a minimum rate of 10 records per second. This may be an XML-only process, or XML+relational if code lookups are done during consolidation.
    •     Allow the records to be viewed and edited, with codes resolved into user-friendly descriptions. Since a user is sitting there, code lookups done when a record is viewed (vs. during consolidation) should not take more than 3 seconds total. We have about 20 code tables averaging a few hundred rows each, though one has 450,000 rows.
    As requested earlier, I have included code at the end of this post for example tables and queries that accurately (but simply) replicate our real system.
    Why we did and why:
    •     Stored the source XML records as CLOBS: We did this to preserve the records exactly as they were certified and sent from providers. In addition, we always access the entire XML record as a whole (e.g., when viewing a record or consolidating employee records), so this storage model seemed like a good fit. We can copy them into another format if necessary.
    •     Stored the consolidated XML employee records as “binary XML”. We did this because we almost always access a single, entire record as a whole (for view/edit), but might want to create some summary statistics at some point. Binary XML seemed the best fit.
    •     Used ora:view() for both tabular source records and lookup tables. We are not aware of any alternatives at this time. If it made sense, most code tables could be pre-converted into XML documents, but this seemed risky from a performance standpoint because the lookups use both code and date range constraints (the meaning of codes changes over time).
    •     Stored records as XMLTYPE columns in a table with other key columns on the table, plus an XMLTYPE metadata column. We thought this would facilitate pulling a single record (or a few records for a given employee) quickly. We knew this might be unnecessary given XML indexes and virtual columns, but were not experienced with those and wanted the comfort of traditional keys. We did not used XMLTYPE tables or the XML Repository for documents.
    •     Used XMLTABLE to consolidate XML records by looping over each distinct employee ID in the source batch. We also tried XMLQUERY and it seems to perform about the same. We can achieve 10 to 20 records/second if we do not do any code lookups during consolidation, just meeting our performance requirement, but still much slower than expected.
    •     Used PL/SQL with XMLFOREST to convert tabular source records to XML by looping over distinct employee IDs. We tried this outside PL/SQL both with XMLFOREST and XMLTABLE+ora:view(), but it hangs in both cases for more than 800 records (a known/open issue). We were able to get it to work by using an explicit cursor to loop over distinct employee IDs (rather than processing all records at once within the query). The performance is one record/second, which is minimally acceptable and interferes with other database activity.
    •     Used XMLQUERY plus ora:view() plus XPATH constraints to perform code lookups. When passing a single employee record, the response time ranges from 1 sec to 160 sec depending on the length of the record (i.e., number of years of service). We achieved a 5-fold speedup using an XMLINDEX (thank you Marco!!). The result may be minimally acceptable, but I’m baffled why the index would be needed when processing a single XML record. Other things we tried: joining code tables in the FOR...WHERE clauses, joining code tables using LET with XPATH constraints and LET with WHERE clause constraints, and looking up codes individually via JDBC from the application code at presentation time. All those approaches were slower. Note: the difference I mentioned above in equality/inequality constraint performance was due to data record variations not query plan variations.
    What issues remain?
    We have a minimally acceptable solution from a performance standpoint with one very awkward PL/SQL workaround. The performance of a mixed XML+relational data query is still marginal IMHO, until we properly utilize available optimizations, fix known problems, and perhaps get some new query optimizations. On the last point, I think the query plan for tabular lookups of codes in XML records is falling short right now. I’m reminded of data warehousing in the days before hash joins and star join optimization. I would be happy to be wrong, and just as happy for viable workarounds if I am right!
    Here are the details on our code lookup challenge. Additional suggestions would be greatly appreciated. I’ll try to post more detail on the legacy table conversion challenge later.
    -- The main record table:
    create table RECORDS (
    SSN varchar2(20),
    XMLREC sys.xmltype
    xmltype column XMLREC store as binary xml;
    create index records_ssn on records(ssn);
    -- A dozen code tables represented by one like this:
    create table CODES (
    CODE varchar2(4),
    DESCRIPTION varchar2(500)
    create index codes_code on codes(code);
    -- Some XML records with coded values (the real records are much more complex of course):
    -- I think this took about a minute or two
    DECLARE
    ssn varchar2(20);
    xmlrec xmltype;
    i integer;
    BEGIN
    xmlrec := xmltype('<?xml version="1.0"?>
    <Root>
    <Id>123456789</Id>
    <Element>
    <Subelement1><Code>11</Code></Subelement1>
    <Subelement2><Code>21</Code></Subelement2>
    <Subelement3><Code>31</Code></Subelement3>
    </Element>
    <Element>
    <Subelement1><Code>11</Code></Subelement1>
    <Subelement2><Code>21</Code></Subelement2>
    <Subelement3><Code>31</Code></Subelement3>
    </Element>
    <Element>
    <Subelement1><Code>11</Code></Subelement1>
    <Subelement2><Code>21</Code></Subelement2>
    <Subelement3><Code>31</Code></Subelement3>
    </Element>
    </Root>
    for i IN 1..100000 loop
    insert into records(ssn, xmlrec) values (i, xmlrec);
    end loop;
    commit;
    END;
    -- Some code data like this (ignoring date ranges on codes):
    DECLARE
    description varchar2(100);
    i integer;
    BEGIN
    description := 'This is the code description ';
    for i IN 1..3000 loop
    insert into codes(code, description) values (to_char(i), description);
    end loop;
    commit;
    end;
    -- Retrieve one record while performing code lookups. Takes about 5-6 seconds...pretty slow.
    -- Each additional lookup (times 3 repeating elements in the data) adds about 1 second.
    -- A typical real record has 5 Elements and 20 Subelements, meaning more than 20 seconds to display the record
    -- Note we are accessing a single XML record based on SSN
    -- Note also we are reusing the one test code table multiple times for convenience of this test
    select xmlquery('
    for $r in Root
    return
    <Root>
    <Id>123456789</Id>
    {for $e in $r/Element
        return
        <Element>
          <Subelement1>
            {$e/Subelement1/Code}
    <Description>
    {ora:view("disaac","codes")/ROW[CODE=$e/Subelement1/Code]/DESCRIPTION/text() }
    </Description>
    </Subelement1>
    <Subelement2>
    {$e/Subelement2/Code}
    <Description>
    {ora:view("disaac","codes")/ROW[CODE=$e/Subelement2/Code]/DESCRIPTION/text()}
    </Description>
    </Subelement2>
    <Subelement3>
    {$e/Subelement3/Code}
    <Description>
    {ora:view("disaac","codes")/ROW[CODE=$e/Subelement3/Code]/DESCRIPTION/text() }
    </Description>
    </Subelement3>
    </Element>
    </Root>
    ' passing xmlrec returning content)
    from records
    where ssn = '10000';
    The plan shows the nested loop access that slows things down.
    By contrast, a functionally-similar SQL query on relational data will use a hash join and perform 10x to 100x faster, even for a single record. There seems to be no way for the optimizer to see the regularity in the XML structure and perform a corresponding optimization in joining the code tables. Not sure if registering a schema would help. Using structured storage probably would. But should that be necessary given we’re working with a single record?
    Operation Object
    |SELECT STATEMENT ()
    | SORT (AGGREGATE)
    | NESTED LOOPS (SEMI)
    | TABLE ACCESS (FULL) CODES
    | XPATH EVALUATION ()
    | SORT (AGGREGATE)
    | NESTED LOOPS (SEMI)
    | TABLE ACCESS (FULL) CODES
    | XPATH EVALUATION ()
    | SORT (AGGREGATE)
    | NESTED LOOPS (SEMI)
    | TABLE ACCESS (FULL) CODES
    | XPATH EVALUATION ()
    | SORT (AGGREGATE)
    | XPATH EVALUATION ()
    | SORT (AGGREGATE)
    | XPATH EVALUATION ()
    | TABLE ACCESS (BY INDEX ROWID) RECORDS
    | INDEX (RANGE SCAN) RECORDS_SSN
    With an xmlindex, the same query above runs in about 1 second, so is about 5x faster (0.2 sec/lookup), which is almost good enough. Is this the answer? Or is there a better way? I’m not sure why the optimizer wants to scan the code tables and index into the (one) XML record, rather than the other way around, but maybe that makes sense if the optimizer wants to use the same general plan as when the WHERE clause constraint is relaxed to multiple records.
    -- Add an xmlindex. Takes about 2.5 minutes
    create index records_record_xml ON records(xmlrec)
    indextype IS xdb.xmlindex;
    Operation Object
    |SELECT STATEMENT ()
    | SORT (GROUP BY)
    | FILTER ()
    | NESTED LOOPS ()
    | FAST DUAL ()
    | TABLE ACCESS (BY INDEX ROWID) SYS113473_RECORDS_R_PATH_TABLE
    | INDEX (RANGE SCAN) SYS113473_RECORDS_R_PATHID_IX
    | SORT (AGGREGATE)
    | FILTER ()
    | TABLE ACCESS (FULL) CODES
    | FILTER ()
    | NESTED LOOPS ()
    | FAST DUAL ()
    | TABLE ACCESS (BY INDEX ROWID) SYS113473_RECORDS_R_PATH_TABLE
    | INDEX (RANGE SCAN) SYS113473_RECORDS_R_PATHID_IX
    | SORT (GROUP BY)
    | FILTER ()
    | NESTED LOOPS ()
    | FAST DUAL ()
    | TABLE ACCESS (BY INDEX ROWID) SYS113473_RECORDS_R_PATH_TABLE
    | INDEX (RANGE SCAN) SYS113473_RECORDS_R_PATHID_IX
    | SORT (AGGREGATE)
    | FILTER ()
    | TABLE ACCESS (FULL) CODES
    | FILTER ()
    | NESTED LOOPS ()
    | FAST DUAL ()
    | TABLE ACCESS (BY INDEX ROWID) SYS113473_RECORDS_R_PATH_TABLE
    | INDEX (RANGE SCAN) SYS113473_RECORDS_R_PATHID_IX
    | SORT (GROUP BY)
    | FILTER ()
    | NESTED LOOPS ()
    | FAST DUAL ()
    | TABLE ACCESS (BY INDEX ROWID) SYS113473_RECORDS_R_PATH_TABLE
    | INDEX (RANGE SCAN) SYS113473_RECORDS_R_PATHID_IX
    | SORT (AGGREGATE)
    | FILTER ()
    | TABLE ACCESS (FULL) CODES
    | FILTER ()
    | NESTED LOOPS ()
    | FAST DUAL ()
    | TABLE ACCESS (BY INDEX ROWID) SYS113473_RECORDS_R_PATH_TABLE
    | INDEX (RANGE SCAN) SYS113473_RECORDS_R_PATHID_IX
    | SORT (AGGREGATE)
    | FILTER ()
    | NESTED LOOPS ()
    | FAST DUAL ()
    | TABLE ACCESS (BY INDEX ROWID) SYS113473_RECORDS_R_PATH_TABLE
    | INDEX (RANGE SCAN) SYS113473_RECORDS_R_PATHID_IX
    | SORT (AGGREGATE)
    | TABLE ACCESS (BY INDEX ROWID) SYS113473_RECORDS_R_PATH_TABLE
    | INDEX (RANGE SCAN) SYS113473_RECORDS_R_PATHID_IX
    | TABLE ACCESS (BY INDEX ROWID) RECORDS
    | INDEX (RANGE SCAN) RECORDS_SSN
    Am I on the right path, or am I totally using the wrong approach? I thought about using XSLT but was unsure how to reference the code tables.
    I’ve done the best I can constraining the main record to a single row passed to the XMLQUERY. Given Mark’s post (thanks!) should I be joining and constraining the code tables in the SQL WHERE clause too? That’s going to make the query much more complicated, but right now we’re more concerned about performance than complexity.

  • How can I use SQL to search for a pattern within a field?

    Hello, Frank, Solomon, ect
    I am now faced with this particular scenario, I've got the SQL to search through a field to find text within the field, but I have to know what it is before it can look for it.
    What I have to do is this:
    Search through a field, for a pattern, and I won't know what the data is I am looking for. Can this be done in SQL?
    For instance, Here is my SQL this far, I was helped allot in order to get to this point.
    select table_name,
           column_name,
           :search_string search_string,
           result
      from (select column_name,
                   table_name,
                   'ora:view("' || table_name || '")/ROW/' || column_name || '[ora:contains(text(),"%' || :search_string || '%") > 0]' str
              from cols
             where table_name in ('TABLE1', 'TABLE2')),
           xmltable (str columns result varchar2(10) path '.')
    When you execute the above SQL, you have to pass in a value. What I really need is to alter the above SQL, to make it search for a pattern that exist's within the text of the field itself.
    Like for instance, lets say the pattern I am looking for is this" xx-xxxxx-xxxx" and it's somewhere in a field.
    I need to alter this SQL to take this pattern and search through all the schemas and tables to look for this pattern match.
    Can be done?

    When you use something dynamically within a function or procedure, roles do not apply and privileges must be granted directly.  So, you need to grant select on dba_tab_cols directly.  If you want to do pattern matching then you should use regular expressions.  The following example grants the proper privileges and uses regexp_instr to find all values containing the pattern xxx-xxxx-xxxx, where /S is used for any non-space character.  I limited the tables in order to save time and output for the test, but you can eliminate that where clause.
    SYS@orcl> CREATE USER test IDENTIFIED BY test
      2  /
    User created.
    SYS@orcl> ALTER USER test QUOTA UNLIMITED ON USERS
      2  /
    User altered.
    SYS@orcl> GRANT CREATE SESSION, CREATE TABLE TO test
      2  /
    Grant succeeded.
    SYS@orcl> GRANT SELECT ON dba_tab_cols TO test
      2  /
    Grant succeeded.
    SYS@orcl> CONNECT test/test
    Connected.
    TEST@orcl> SET LINESIZE 90
    TEST@orcl> CREATE TABLE table1
      2    (tab1_col1  VARCHAR2(60))
      3  /
    Table created.
    TEST@orcl> INSERT ALL
      2  INTO table1 (tab1_col1) VALUES ('xxx-xxxx-xxxx')
      3  INTO table1 (tab1_col1) VALUES ('matching abc-defg-hijk data')
      4  INTO table1 (tab1_col1) VALUES ('other data')
      5  SELECT * FROM DUAL
      6  /
    3 rows created.
    TEST@orcl> CREATE TABLE table2
      2    (tab2_col2  VARCHAR2(30))
      3  /
    Table created.
    TEST@orcl> INSERT ALL
      2  INTO table2 (tab2_col2) VALUES ('this BCD-EFGH-IJKL too')
      3  INTO table2 (tab2_col2) VALUES ('something else')
      4  SELECT * FROM DUAL
      5  /
    2 rows created.
    TEST@orcl> VAR search_string VARCHAR2(24)
    TEST@orcl> EXEC :search_string := '\S\S\S-\S\S\S\S-\S\S\S\S'
    PL/SQL procedure successfully completed.
    TEST@orcl> COLUMN "Searchword"     FORMAT A24
    TEST@orcl> COLUMN "Table"     FORMAT A6
    TEST@orcl> COLUMN "Column/Value" FORMAT A50
    TEST@orcl> SELECT DISTINCT SUBSTR (:search_string, 1, 24) "Searchword",
      2               SUBSTR (table_name, 1, 14) "Table",
      3               SUBSTR (t.column_value.getstringval (), 1, 50) "Column/Value"
      4  FROM   dba_tab_cols,
      5          TABLE
      6            (XMLSEQUENCE
      7           (DBMS_XMLGEN.GETXMLTYPE
      8              ( 'SELECT ' || column_name ||
      9               ' FROM ' || table_name ||
    10               ' WHERE REGEXP_INSTR
    11                     (UPPER (' || column_name || '),''' ||
    12                  UPPER (:search_string) || ''') > 0'
    13              ).extract ('ROWSET/ROW/*'))) t
    14  WHERE  table_name IN ('TABLE1', 'TABLE2')
    15  ORDER  BY "Table"
    16  /
    Searchword               Table  Column/Value
    \S\S\S-\S\S\S\S-\S\S\S\S TABLE1 <TAB1_COL1>matching abc-defg-hijk data</TAB1_COL1>
    \S\S\S-\S\S\S\S-\S\S\S\S TABLE1 <TAB1_COL1>xxx-xxxx-xxxx</TAB1_COL1>
    \S\S\S-\S\S\S\S-\S\S\S\S TABLE2 <TAB2_COL2>this BCD-EFGH-IJKL too</TAB2_COL2>
    3 rows selected.

  • How to display the NULL records by multiple XMLTABLE()

    First, let me provide the testing data of INSERT and CREATE TABLE sql:
    create table xml_t2 (xml_raw XMLTYPE);insert sql, a bit long.....just copy and paste then run it will be OK!
    the system warns: Your message exceeds the maximum length of 30000 characters.
    So, I place it on the mediafire shariing space
    http://www.mediafire.com/?npmot6lgl86dgliTesting SQL:
    SELECT t1.years, t1.months,t1.days,t1.hours,t1.value,t2.value
            FROM xml_t2,
            XMLTABLE ('$d/cdata/F1' passing xml_raw as "d" COLUMNS years integer path '//year', months varchar(3) path '//month', days varchar(2) path '//day', hours varchar(2) path '//hour', mins varchar(2) path '//minute', value float path '//value') t1 ,
            XMLTABLE ('$d/cdata/F2' passing xml_raw as "d" COLUMNS years integer path '//year', months varchar(3) path '//month', days varchar(2) path '//day', hours varchar(2) path '//hour', mins varchar(2) path '//minute', value float path '//value') t2The condition for now is....In the xml data, I have deleted the month 'Jan' with <F2>tag which is in 2010.
    That mean the output of XMLTABLE t2 will not contain the 'Jan' records but it is still remain in XMLTABLE t1.
    The problem is that when I use the above SQL to show the t1.value, it will not display the t1.value in 2010 Jan.....it just skipped 'Jan' and becomes 'Feb'...
    what i would prefer to display is something like this:
    YEARS MONTHS DAYS HOURS t1_value t2_value
    2009     Jan    01   01       8       8
    2009     Jan    01   02       8     580
    2009     Jan    02   01     580     580
    2009     Jan    02   02     580     580
    2009     Feb    01   01     440     440
    2010     Jan    01   01     627     NULL
    2010     Jan    01   02     627     NULL
    2010     Jan    02   01     367     NULL
    2010     Jan    02   02     367     NULL
    2010     Feb    01   01     367     849
    2010     Feb    01   02     849     849
    ..............So...the main problem is how to display back the record in JAN in 2010 in t1 XMLTABLE and assign null to the t2 XMLTABLE since it doen't contains this months record.
    THANKS for help!!

    Hi,
    What's your database version?
    Are you using binary XML storage? (This is the default in 11.2.0.2)
    If not you have to explicitely specify it :
    create table xml_t2 (xml_raw XMLTYPE)
    xmltype column xml_raw store as securefile binary xml;Along with object-relational, it's the best storage strategy to use in conjunction with XMLIndex.
    You should also use a structured XML index instead, it's more appropriate than the unstructured index you're currently using :
    create index xml_t2_sxi on xml_t2 (xml_raw)
    indextype is xdb.xmlindex
    parameters (q'#
    XMLTABLE xml_t2_xt '/cdata'
    COLUMNS
    YEARS  INTEGER    PATH 'F1/name/year',
    MONTHS VARCHAR(3) PATH 'F1/name/month',
    DAYS   VARCHAR(2) PATH 'F1/name/day',
    HOURS  VARCHAR(2) PATH 'F1/name/hour',
    MINS   VARCHAR(2) PATH 'F1/name/minute',
    VALUE  FLOAT      PATH 'F1/name/value',
    VALUE2 FLOAT      PATH 'F2/name/value'
    call dbms_stats.gather_table_stats(user, 'XML_T2');Use the query provided by Stew and check the explain plan, you'll see the difference.

  • How do I Load a clob from an XML field in an XMLTYPE using XMLTABLE ?

    I am trying to load data into a CLOB from a XML field using XMLTABLE.
    I have a SUMMARY xml field with over 100 K of data (potentialy)
    and I can load all the other datatype fields to columns but can not load the xml fields over 4000 characters.
    example
    First I create a table of XMLTYPE. I need to sqlload new files in at regular intervals.
    Create table WEB_XML of XMLTYPE;
    Then I create my relational table....
    create table WEB_WORKING
    request_id varchar(10),
    ref_number varchar(20),
    summary clob
    The I use the .ctl file to sqlload the xml data in
    LOAD DATA
    INFILE *
    INTO TABLE WEB_XML
    append
    xmltype(XMLDATA)
    ext_fname filler char(90),
    XMLDATA LOBFILE(ext_fname) TERMINATED BY EOF
    BEGINDATA
    XMLFILE1.xml
    After loading the WEB_XML table using sqlldr, I try to load my relational table using XMLTable
    INSERT into WEBBAR_WORKING
    request_id ,
    ref_number ,
    summary
    SELECT X.* FROM WEB_XML P2,
    XMLTable ( '//Request//REQUESTVIEW'
    PASSING P2.object_value
    COLUMNS
    "request_id" VARCHAR(10) PATH 'REQUEST_ID',
    "ref_number" VARchar(20) PATH 'REF_NUMBER',
    "SUMMARY" clob PATH 'SUMMARY'
    ) AS X;
    This gives an error saying its not expecting clob
    My XML looks somthing like
    -<Request>
    -<REQUESTVIEW>
    <REQUEST_ID>3140</REQUEST_ID>
    <ref_number>2003-04-02</RECEIVED_DATE>
    <SUMMARY>
    OVER 100 K of data
    </SUMMARY>
    </REQUESTVIEW>
    </Request>

    ok
    that helped lot, im getting there however some more help please
    This SQL
    SELECT request_id, recieved_by, X.SUMMARY.getClobVal()
    FROM WEB_XML P2,
    XMLTable
    '//Request//REQUESTVIEW'
    PASSING P2.object_value
    COLUMNS
    "request_id" VARCHAR(10) PATH 'REQUEST_ID',
    "received_by" VARCHAR(10) PATH 'RECEIVED_BY',
    "SUMMARY" xmltype PATH 'SUMMARY'
    ) AS X;
    SELECT request_id, recieved_by, X.SUMMARY.getClobVal()
    ERROR at line 1:
    ORA-00904: "RECIEVED_BY": invalid identifier
    If I use the X.request_id, X.received_by ......
    i get the error message
    Package or function is in aan invalid state.
    But this SQL was successful in getting the clob by itself but with the XML tgs around it still, how do I strip the XML tags from around this result ?
    SELECT X.SUMMARY.getClobVal()
    FROM WEBBAR_XML P2,
    XMLTable
    '//Request//REQUESTVIEW'
    PASSING P2.object_value
    COLUMNS
    "SUMMARY" XMLTYPE PATH 'SUMMARY'
    ) AS X;
    ----------------------------------------------------------

  • How to load a XML file into a table using PL/SQL

    Hi Guru,
    I have a requirement, that i have to create a procedure or a package in PL/SQL to load  XML file into a table.
    How we can achive this.

    ODI_NewUser wrote:
    Hi Guru,
    I have a requirement, that i have to create a procedure or a package in PL/SQL to load  XML file into a table.
    How we can achive this.
    Not a perfectly framed question. How do you want to load the XML file? Hoping you want to parse the xml file and load it into a table you can do this.
    This is the xml file
    karthick% cat emp_details.xml
    <?xml version="1.0"?>
    <ROWSET>
    <ROW>
      <EMPNO>7782</EMPNO>
      <ENAME>CLARK</ENAME>
      <JOB>MANAGER</JOB>
      <MGR>7839</MGR>
      <HIREDATE>09-JUN-1981</HIREDATE>
      <SAL>2450</SAL>
      <COM>0</COM>
      <DEPTNO>10</DEPTNO>
    </ROW>
    <ROW>
      <EMPNO>7839</EMPNO>
      <ENAME>KING</ENAME>
      <JOB>PRESIDENT</JOB>
      <HIREDATE>17-NOV-1981</HIREDATE>
      <SAL>5000</SAL>
      <COM>0</COM>
      <DEPTNO>10</DEPTNO>
    </ROW>
    </ROWSET>
    You can write a query like this.
    SQL> select *
      2    from xmltable
      3         (
      4            '/ROWSET/ROW'  passing xmltype
      5            (
      6                 bfilename('SDAARBORDIRLOG', 'emp_details.xml')
      7               , nls_charset_id('AL32UTF8')
      8            )
      9            columns empno    number      path 'EMPNO'
    10                  , ename    varchar2(6) path 'ENAME'
    11                  , job      varchar2(9) path 'JOB'
    12                  , mgr      number      path 'MGR'
    13                  , hiredate varchar2(20)path 'HIREDATE'
    14                  , sal      number      path 'SAL'
    15                  , com      number      path 'COM'
    16                  , deptno   number      path 'DEPTNO'
    17         );
         EMPNO ENAME  JOB              MGR HIREDATE                    SAL        COM     DEPTNO
          7782 CLARK  MANAGER         7839 09-JUN-1981                2450          0         10
          7839 KING   PRESIDENT            17-NOV-1981                5000          0         10
    SQL>

Maybe you are looking for