Conversion of a Base64EncodedXML CLOB to XMLTYPE

I have an xml file which is base64 encoded and the base64 encoded file is stored as a clob. I want to do all the manipulation in PL/SQL and modify the clob column with one of xmltype
Heres the steps I've got so far:
i) convert the clob to a blob using dbms_lob.converttoclob
ii) Since this is now in binary format I'm asusming that I don't need to cast to raw
iii) decode the binary file using UTL_ENCODE.base64_decode
iv) add an additional column  temp_xml as type xml_type
v) update the temp_xml column with the values of the original column.
update <tablename>
               set temp_xml = xmltype(orig_clob_column) vi) At this stage I will see if I can read the xml in the new column and if all is successful, I will drop the orig_clob_column and rename temp_xml to orig_clob_column.
If I've missed anything or anyone's got some gotchas for me, it would be appreciated.
Message was edited by:
Keith Jamieson
Message was edited by:
Keith Jamieson

I am using Oracle 11g Windows and based on the example here:
http://www.peakretrieval.com/plsql/Chapter16/Convert.sql
create or replace PROCEDURE CONVERT_ME (
   v_blob_or_clob IN NUMBER,
   v_blob IN OUT BLOB,
   v_clob IN OUT CLOB,
   v_amount IN OUT NUMBER,
   v_blob_offset IN OUT NUMBER,
   v_clob_offset IN OUT NUMBER,
   v_lang_context IN OUT NUMBER,
   v_warning OUT NUMBER)
AS
BEGIN
   DBMS_LOB.OPEN(v_blob, DBMS_LOB.LOB_READWRITE);
   DBMS_LOB.OPEN(v_clob, DBMS_LOB.LOB_READWRITE);
   IF v_blob_or_clob = 0
   THEN
   DBMS_LOB.CONVERTTOBLOB(v_blob,
                          v_clob,
                          v_amount,
                          v_blob_offset,
                          v_clob_offset,
                          1,
                          v_lang_context,
                          v_warning);
   ELSE
   DBMS_LOB.CONVERTTOCLOB(v_clob,
                          v_blob,
                          v_amount,
                          v_clob_offset,
                          v_blob_offset,
                          1,
                          v_lang_context,
                          v_warning);
   END IF;
   DBMS_LOB.CLOSE(v_blob);
   DBMS_LOB.CLOSE(v_clob);
END;When I run this sample code
DECLARE
   v_clob_or_blob NUMBER;
   v_blob_locator BLOB;
   v_clob_locator CLOB;
   v_blob_offset NUMBER;
   v_clob_offset NUMBER;
   v_lang_context NUMBER := DBMS_LOB.DEFAULT_LANG_CTX;
   v_warning NUMBER;
   v_string_length NUMBER(10);
   v_source_locator BLOB;
   v_destination_locator BLOB;
   v_amount PLS_INTEGER;
   v_string CLOB;
BEGIN
   -- CONVERT CLOB TO BLOB
   SELECT description
   INTO v_clob_locator
   FROM book_samples
   WHERE book_sample_id = 1
   FOR UPDATE;
   SELECT misc
   INTO v_blob_locator
   FROM book_samples
   WHERE book_sample_id = 1
   FOR UPDATE;
   v_string_length := DBMS_LOB.GETLENGTH(v_blob_locator);
   v_amount := DBMS_LOB.GETLENGTH(v_clob_locator);
   DBMS_OUTPUT.PUT_LINE('The initial length of the BLOB is: '||v_string_length);
        v_clob_or_blob := 0; -- Convert clob to blob
        v_clob_offset := 1;
        v_blob_offset := 1;
        CONVERT_ME(v_clob_or_blob,
                v_blob_locator,
                v_clob_locator,
                v_amount,
                v_blob_offset,
                v_clob_offset,
                v_lang_context,
                v_warning);
   v_string_length := DBMS_LOB.GETLENGTH(v_blob_locator);
   DBMS_OUTPUT.PUT_LINE('The length of the BLOB post-conversion is: '||v_string_length);
   -- COPY BLOB FOR ONE ROW TO BLOB IN ANOTHER
   v_source_locator := v_blob_locator;
   SELECT misc
   INTO v_destination_locator
   FROM book_samples
   WHERE book_sample_id = 2
   FOR UPDATE;
   DBMS_LOB.COPY(v_destination_locator, v_source_locator, 32768, 1, 1);
   v_string_length := DBMS_LOB.GETLENGTH(v_destination_locator);
   DBMS_OUTPUT.PUT_LINE('The length of the BLOB post-copy is: '||v_string_length);
   -- COPY BLOB FOR RECORD 2 BACK TO A CLOB
   SELECT description
   INTO v_clob_locator
   FROM book_samples
   WHERE book_sample_id = 2
   FOR UPDATE;
   SELECT misc
   INTO v_blob_locator
   FROM book_samples
   WHERE book_sample_id = 2
   FOR UPDATE;
   v_string_length := DBMS_LOB.GETLENGTH(v_clob_locator);
   v_amount := DBMS_LOB.GETLENGTH(v_blob_locator);
   DBMS_OUTPUT.PUT_LINE('The initial length of the CLOB (record 2) is: '||v_string_length);
        v_clob_or_blob := 1; -- Convert blob to clob
        v_clob_offset := 1;
        v_blob_offset := 1;
        CONVERT_ME(v_clob_or_blob,
                v_blob_locator,
                v_clob_locator,
                v_amount,
                v_clob_offset,
                v_blob_offset,
                v_lang_context,
                v_warning);
   v_string_length := DBMS_LOB.GETLENGTH(v_clob_locator);
   SELECT description
   INTO v_string
   FROM book_samples
   WHERE book_sample_id = 2;
   DBMS_OUTPUT.PUT_LINE('The length of the CLOB post-conversion is: '||v_string_length);
   DBMS_OUTPUT.PUT_LINE('     ');
   DBMS_OUTPUT.PUT_LINE('The converted CLOB');
   DBMS_OUTPUT.PUT_LINE('==================');
   DBMS_OUTPUT.PUT_LINE(SUBSTR(v_string,1,150));
   DBMS_OUTPUT.PUT_LINE(SUBSTR(v_string,151,300));
EXCEPTION
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.PUT_LINE('I''M BROKEN ... FIX ME!');
      DBMS_OUTPUT.PUT_LINE(SQLERRM);
END;I get the following error:
Length of blob before conversion
The conver_me procedure is broken ...
ORA-06502: PL/SQL: numeric or value error: invalid LOB locator specified: ORA-22275
Length of blob after conversion

Similar Messages

  • Convert clob to xmltype

    Hi
    How to convert data CLOB datatype to XMLTYPE Datatype
    Ex: field col1 has clob data type
    any possible to convert col1 in target table col1 xmltype datatype
    Regards,
    Venkat

    Hi Venkat,
    Please try the following:
    CREATE TABLE CLOBTABLE (
    CLOBCOL1 CLOB
    INSERT INTO clobtable VALUES ('<?xml version="1.0"?> <EMP> <EMPNO>2</EMPNO> <ENAME>Sumeet</ENAME> </EMP>');
    CREATE OR REPLACE FUNCTION to_xmltype (clobcol CLOB) RETURN XMLTYPE AS
    BEGIN
    RETURN XMLType(clobcol);
    END;
    SELECT to_xmltype(clobcol) FROM clobtab;

  • Convert CLOB to XMLType in SELECT statement ?

    Hi XML Xperts,
    In my Oracle 9.2.0.3 I have 1 table (tab1) with 2 cols (col1 as XMLType and col2 as CLOB). I Inserted in both fields the following same XML data :
    <?xml version="1.0"?>
    <TABLE_NAME>MY_TABLE</TABLE_NAME>
    With the following statement, I can get the data from col1 which is a XMLType column :
    SELECT a.col1.extract('//TABLE_NAME/text()').getStringVal() AS "Table Name"
    FROM tab1 a
    WHERE a.col1.existsNode('/TABLE_NAME') = 1;
    How to get the same data FROM col2 whcih is a CLOB column ? Is it possible to transform the CLOB to XMLType in the SELECT statement ?
    Note : I cannot change the type of the colulmn col2 to XMLType
    Thanks in advance.
    Phil

    I tested it in 10g and it seems to be OK.
    create table clobtoxml(xmldata clob);
    insert into clobtoxml
    values('<RootE><FirstNode>This is CLOB data to XML</FirstNode></RootE>');
    commit;
    select sys.xmltype(xmldata).extract('/RootE/FirstNode/text()').getStringVal() from clobtoxml;
    This is CLOB data to XML
    select sys.xmltype(xmldata).extract('/*') from clobtoxml;
    <RootE>
    <FirstNode>This is CLOB data to XML</FirstNode>
    </RootE>
    Ben

  • 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.

  • How to convert CLOB to XMLType ??

    Hi,
    I created a table XML_TAB as
    SQL> desc xml_tab;
    Name Null? Type
    DOCID NUMBER
    DTD CLOB
    XMLDOC CLOB
    VALID NUMBER
    and I inserted a record in the table.
    Now the file inserted at the column XMLDOC, I want to convert it to XMLType. How can I do that.
    Some docs says to user XMLType.createXML function......
    But when I did it....................
    SQL> select xmltype.createxml(xmldoc) from xml_tab
    ERROR:
    ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00210: expected '<' instead of '<'
    Error at line 1
    ORA-06512: at "SYS.XMLTYPE", line 0
    ORA-06512: at line 1
    What could be the cause of the problem? Am I doing it in a correct way?
    -- Jitendra

    The main difference between CLOB and XMLType is that XMLType always contain a well formed XML document.
    So if CLOB doesn't complain , then XMLType does.

  • Which is better - BLOB, CLOB or XMLTYPE?

    Hi All,
    We have to store XML in one of the fields in our table.
    XML size is not fix but its not so huge that we shold go for external LOBs.
    I mean it will be alwas less than 4G.
    Our concern here is, does CLOB allocates exactly as much memory needed as much the data is present,(something like VARCHAR2).
    How is it in case of BLOB and XMLTYPE as well?
    Is there any Oracle documentation or way (code snippet) to verify this?
    Thanks in advnace.
    Avinash.

    You have asked if CLOB allocates space like VARCHAR2 - yes it does. Maybe this example will be better:
    SQL> TRUNCATE TABLE test_table;
    Tabela zosta│a obciŕta.
    SQL> insert into test_table values(LPAD('A', 100, 'A'));
    1 wiersz zosta│ utworzony.
    SQL> insert into test_table values(LPAD('A', 1000, 'A'));
    1 wiersz zosta│ utworzony.
    SQL> insert into test_table values(LPAD('A', 10000, 'A'));
    1 wiersz zosta│ utworzony.
    SQL> COMMIT;
    Zatwierdzanie zosta│o uko˝czone.
    SQL> SELECT LENGTH(col1) FROM test_table;
    LENGTH(COL1)
             100
            1000
            4000
    SQL>

  • Extract part of xml into CLOB or XMLType

    I need to extract part of XML into CLOB or some another type. But I don't need only extract data, by whole part od xml with elements. How could I do it in PL/SQL?
    For example from this xml:
    <bookstore>
    <book category="COOKING">
    <title lang="en">Everyday Italian</title>
    <author>Giada De Laurentiis</author>
    <year>2005</year>
    <price>30.00</price>
    </book>
    <book category="CHILDREN">
    <title lang="en">Harry Potter</title>
    <author>J K. Rowling</author>
    <year>2005</year>
    <price>29.99</price>
    </book>
    </bookstore>
    I need to get:
    "<book category="COOKING">
    <title lang="en">Everyday Italian</title>
    <author>Giada De Laurentiis</author>
    <year>2005</year>
    <price>30.00</price>
    </book>"
    THX

    That's why I need to process every book alone - to know which authors belongs to single book.For that specific requirement, a single query would do.
    Assuming variable "v_xml_clob" holds the XML document :
    <bookstore>
      <name>nameOfBookstore</name>
      <address>1st Avenue 24, SF</address>
          <book category="COOKING">
            <title lang="en">Everyday Italian</title>
            <author>
              <name>Giada De Laurentiis</name>
              <birth>1956</birth>
            </author>
            <author>
              <name>xxx</name>
              <birth>1955</birth>
            </author>
            <year>2005</year>
            <price>30.00</price>
          </book>
          <book category="CHILDREN">
            <title lang="en">Harry Potter</title>
            <author>
              <name>Rowning</name>
              <birth>1977</birth>
            </author>
            <author>
              <name>xxx</name>
              <birth>1955</birth>
            </author>
            <year>2005</year>
            <price>29.99</price>
          </book>
    </bookstore>You can do :
    SELECT *
    FROM XMLTable(
    'for $i in distinct-values($d//book/author/name)
      where count($d//book/author[name=$i]) = 1
      return $i'
    passing xmltype(v_xml_clob) as "d"
    columns author_name varchar2(80) path '.'
    AUTHOR_NAME
    Rowning
    Giada De Laurentiis

  • How to insert data into clob or xmltype column

    when i am inserting to clob or xml type column i am getting error like ERROR at line 2:
    ORA-01704: string literal too long
    INSERT INTO po_clob_tab
    values(100,'<TXLife>
         <UserAuthRequest>
              <UserLoginName>UserId</UserLoginName>
         </UserAuthRequest>
         <TXLifeRequest>
              <TransRefGUID>0099962A-BFF3-4761-4058-F683398D79F7</TransRefGUID>
              <TransType tc="186">OLI_TRANS_CHGPAR</TransType>
              <TransExeDate>2008-05-29</TransExeDate>
              <TransExeTime>12:01:01</TransExeTime>
              <InquiryLevel tc="3">OLI_INQUIRY_OBJRELOBJ</InquiryLevel>
              <InquiryView>
                   <InquiryViewCode>CU186A</InquiryViewCode>
              </InquiryView>
              <ChangeSubType>
                   <ChangeTC tc="32">Update / Add Client Object Information</ChangeTC>
                   <!--TranContentCode tc = 1 (Add)
                                                           tc = 2 (Update)
                                                           tc = 3 (Delete)
                   -->
                   <TranContentCode tc="1">Add</TranContentCode>
              </ChangeSubType>
              <OLifE>
                   <SourceInfo>
                        <SourceInfoName>Client Profile</SourceInfoName>
                   </SourceInfo>
                   <Activity id="Act1" PartyID="Party1">
                        <ActivityStatus tc="2">In Progress</ActivityStatus>
                        <UserCode>123456</UserCode>
                        <Opened>2010-08-17</Opened>
                        <ActivityCode>CP10001</ActivityCode>
                        <Attachment>
                             <Description>LastScreenName</Description>
                             <AttachmentData>CP Create</AttachmentData>
                             <AttachmentType tc="2">OLI_ATTACH_COMMENT </AttachmentType>
                             <AttachmentLocation tc="1">OLI_INLINE </AttachmentLocation>
                        </Attachment>
                        <OLifEExtension VendorCode="05" ExtensionCode="Activity">
                             <ActivityExtension>
                                  <SubActivityCode>CP20001</SubActivityCode>
                             </ActivityExtension>
                        </OLifEExtension>
                   </Activity>
                   <Grouping id="Grouping1">
                        <Household>
                             <EstIncome>90000</EstIncome>
                        </Household>
                   </Grouping>
                   <Holding id="Holding1">
                        <HoldingTypeCode tc="2">Policy</HoldingTypeCode>
                        <Purpose tc="35">Accumulation</Purpose>
                        <Policy>
                             <ProductType tc="1009800001">AXA Network Non-Proprietary Variable Life Product</ProductType>
                             <ProductCode>Plus9</ProductCode>
                             <PlanName>Accumulator Plus 9.0</PlanName>
                             <Annuity>
                                  <QualPlanType tc="45">Qualified</QualPlanType>
                             </Annuity>
                             <ApplicationInfo>
                                  <ApplicationJurisdiction tc="35">New Jersey</ApplicationJurisdiction>
                                  <OLifEExtension VendorCode="05" ExtensionCode="ApplicationInfo">
                                       <ApplicationInfoExtension>
                                            <FinancialPlanIInd tc="0">False</FinancialPlanIInd>
                                            <AgentVerifiesOwnersID tc="1">True</AgentVerifiesOwnersID>
                                       </ApplicationInfoExtension>
                                  </OLifEExtension>
                             </ApplicationInfo>
                             <FinancialActivity>
                                  <FinActivityType tc="7">Initial Payment</FinActivityType>
                                  <FinActivityPct>10</FinActivityPct>
                                  <Payment>
                                       <SourceOfFundsTC tc="18">Gift</SourceOfFundsTC>
                                       <OLifEExtension VendorCode="05" ExtensionCode="Payment">
                                            <PaymentExtension>
                                                 <FundingDisclosureDetails>
                                                      <FundingDisclosureTC tc="1009800001">Cash</FundingDisclosureTC>
                                                 </FundingDisclosureDetails>
                                            </PaymentExtension>
                                       </OLifEExtension>
                                  </Payment>
                             </FinancialActivity>
                             <FinancialActivity>
                                  <FinActivityType tc="7">Initial Payment</FinActivityType>
                                  <FinActivityPct>10</FinActivityPct>
                                  <Payment>
                                       <SourceOfFundsTC tc="8">Personal Loan</SourceOfFundsTC>
                                       <OLifEExtension VendorCode="05" ExtensionCode="Payment">
                                            <PaymentExtension>
                                                 <FundingDisclosureDetails>
                                                      <FundingDisclosureTC tc="1009800002">Borrowing</FundingDisclosureTC>
                                                 </FundingDisclosureDetails>
                                            </PaymentExtension>
                                       </OLifEExtension>
                                  </Payment>
                             </FinancialActivity>
                             <FinancialActivity>
                                  <FinActivityType tc="7">Initial Payment</FinActivityType>
                                  <FinActivityPct>10</FinActivityPct>
                                  <Payment>
                                       <SourceOfFundsTC tc="10">Withdrawal</SourceOfFundsTC>
                                       <OLifEExtension VendorCode="05" ExtensionCode="Payment">
                                            <PaymentExtension>
                                                 <FundingDisclosureDetails>
                                                      <FundingDisclosureTC tc="1009800003">Policy Related</FundingDisclosureTC>
                                                 </FundingDisclosureDetails>
                                            </PaymentExtension>
                                       </OLifEExtension>
                                  </Payment>
                             </FinancialActivity>
                             <FinancialActivity>
                                  <FinActivityType tc="7">Initial Payment</FinActivityType>
                                  <FinActivityPct>10</FinActivityPct>
                                  <Payment>
                                       <OLifEExtension VendorCode="05" ExtensionCode="Payment">
                                            <PaymentExtension>
                                                 <FundingDisclosureDetails>
                                                      <FundingDisclosureTC tc="1009800005">Sale of 401(k) Mutual Fund Shares, Existing Pension Plan Assets, Stocks, Bonds, CD’s</FundingDisclosureTC>
                                                 </FundingDisclosureDetails>
                                            </PaymentExtension>
                                       </OLifEExtension>
                                  </Payment>
                             </FinancialActivity>
                             <FinancialActivity>
                                  <FinActivityType tc="7">Initial Payment</FinActivityType>
                                  <FinActivityPct>10</FinActivityPct>
                                  <Payment>
                                       <OLifEExtension VendorCode="05" ExtensionCode="Payment">
                                            <PaymentExtension>
                                                 <FundingDisclosureDetails>
                                                      <FundingDisclosureTC tc="1009800004">Sale of qualified or non-qualified Mutual Fund Shares</FundingDisclosureTC>
                                                 </FundingDisclosureDetails>
                                            </PaymentExtension>
                                       </OLifEExtension>
                                  </Payment>
                             </FinancialActivity>
                             <FinancialActivity>
                                  <FinActivityType tc="7">Initial Payment</FinActivityType>
                                  <FinActivityPct>20</FinActivityPct>
                                  <Payment>
                                       <OLifEExtension VendorCode="05" ExtensionCode="Payment">
                                            <PaymentExtension>
                                                 <FundingDisclosureDetails>
                                                      <FundingDisclosureTC tc="1009800006">Sale of Investment Advisory Assets</FundingDisclosureTC>
                                                 </FundingDisclosureDetails>
                                            </PaymentExtension>
                                       </OLifEExtension>
                                  </Payment>
                             </FinancialActivity>
                             <FinancialActivity>
                                  <FinActivityType tc="7">Initial Payment</FinActivityType>
                                  <FinActivityPct>20</FinActivityPct>
                                  <Payment>
                                       <SourceOfFundsTC tc="1009800008">Car</SourceOfFundsTC>
                                       <OLifEExtension VendorCode="05" ExtensionCode="Payment">
                                            <PaymentExtension>
                                                 <FundingDisclosureDetails>
                                                      <FundingDisclosureTC tc="2147483647">Other</FundingDisclosureTC>
                                                 </FundingDisclosureDetails>
                                            </PaymentExtension>
                                       </OLifEExtension>
                                  </Payment>
                             </FinancialActivity>
                        </Policy>
                   </Holding>
                   <Party id="Party1">
                        <PartyTypeCode tc="1">Person</PartyTypeCode>
                        <EstNetWorth>250000</EstNetWorth>
                        <LiquidNetWorthAmt>120000</LiquidNetWorthAmt>
                        <EstTotAssetsAmt>400000</EstTotAssetsAmt>
                        <Person>
                             <FirstName>John</FirstName>
                             <LastName>Doe</LastName>
                             <MarStat tc="1">Married</MarStat>
                             <Gender tc="1">Male</Gender>
                             <BirthDate>1965-05-07</BirthDate>
                             <EducationType tc="3">Associate Degree</EducationType>
                             <Citizenship tc="1">USA</Citizenship>
                             <NetIncomeAmt>70000</NetIncomeAmt>
                             <DriversLicenseNum>D123456789</DriversLicenseNum>
                             <DriversLicenseState tc="35">New Jersey</DriversLicenseState>
                             <ImmigrationStatus tc="8">Citizen</ImmigrationStatus>
                             <DriversLicenseExpDate>2012-05-25</DriversLicenseExpDate>
                             <OLifEExtension VendorCode="05" ExtensionCode="Person">
                                  <PersonExtension>
                                       <NoDriversLicenseInd tc="0">False</NoDriversLicenseInd>
                                  </PersonExtension>
                             </OLifEExtension>
                        </Person>
                        <Address>
                             <Line1>125 Finn Lane</Line1>
                             <City>North Brunswick</City>
                             <AddressStateTC tc="35">New Jersey</AddressStateTC>
                             <Zip>08902</Zip>
                        </Address>
                        <Phone>
                             <PhoneTypeCode tc="1">Home</PhoneTypeCode>
                             <DialNumber>732456789</DialNumber>
                        </Phone>
                        <Phone>
                             <PhoneTypeCode tc="2">Work</PhoneTypeCode>
                             <DialNumber>732987654</DialNumber>
                        </Phone>
                        <Attachment>
                             <Description>Comments</Description>
                             <AttachmentData>This is the comments entered for the client</AttachmentData>
                             <AttachmentType tc="2">OLI_ATTACH_COMMENT </AttachmentType>
                             <AttachmentLocation tc="1">OLI_INLINE </AttachmentLocation>
                        </Attachment>
                        <Attachment>
                             <AttachmentSysKey>1</AttachmentSysKey>
                             <Description>Additional Notes Important Considerations</Description>
                             <AttachmentData>This is the comments entered for the client</AttachmentData>
                             <AttachmentType tc="2">OLI_ATTACH_COMMENT </AttachmentType>
                             <AttachmentLocation tc="1">OLI_INLINE </AttachmentLocation>
                        </Attachment>
                        <Attachment>
                             <AttachmentSysKey>2</AttachmentSysKey>
                             <Description>Additional Notes Important Considerations</Description>
                             <AttachmentData>This is the comments entered for the client</AttachmentData>
                             <AttachmentType tc="2">OLI_ATTACH_COMMENT </AttachmentType>
                             <AttachmentLocation tc="1">OLI_INLINE </AttachmentLocation>
                        </Attachment>
                        <Client>
                             <NumRelations>1</NumRelations>
                             <EstTaxBracket>10</EstTaxBracket>
                             <BrokerDealerInd tc="1">True</BrokerDealerInd>
                             <EstIncomeAmt>90000</EstIncomeAmt>
                             <PrimaryInvObjective tc="8">Income and Growth</PrimaryInvObjective>
                             <InvHorizonRangeMin>5</InvHorizonRangeMin>
                             <OLifEExtension VendorCode="05" ExtensionCode="Client">
                                  <ClientExtension>
                                       <RiskToleranceCode tc="3">Moderate</RiskToleranceCode>
                                       <FINRAAffiliationName>John Doe</FINRAAffiliationName>
                                       <Rank>
                                            <RankCategory tc="1009800001">Financial Goal</RankCategory>
                                            <TotalRankCode>5</TotalRankCode>
                                            <RankCode PurposeID="1009800016">6</RankCode>
                                            <RankCode PurposeID="35">6</RankCode>
                                            <RankCode PurposeID="2">6</RankCode>
                                            <RankCode PurposeID="1009800013">6</RankCode>
                                            <RankCode PurposeID="1009800014">6</RankCode>
                                            <RankCode PurposeID="5">6</RankCode>
                                            <RankCode PurposeID="1009800015">6</RankCode>
                                       </Rank>
                                  </ClientExtension>
                             </OLifEExtension>
                        </Client>
                        <EMailAddress>
                             <EMailType tc="1">Business</EMailType>
                             <AddrLine>[email protected]</AddrLine>
                        </EMailAddress>
                        <Risk>
                             <HHFamilyInsurance>
                                  <HHFamilyInsuranceSysKey>1</HHFamilyInsuranceSysKey>
                                  <DeclinedInd tc="0">False</DeclinedInd>
                                  <LineOfBusiness tc="1">Life Insurance</LineOfBusiness>
                             </HHFamilyInsurance>
                             <HHFamilyInsurance>
                                  <HHFamilyInsuranceSysKey>2</HHFamilyInsuranceSysKey>
                                  <DeclinedInd tc="0">False</DeclinedInd>
                                  <LineOfBusiness tc="1">Life Insurance</LineOfBusiness>
                             </HHFamilyInsurance>
                             <HHFamilyInsurance>
                                  <HHFamilyInsuranceSysKey>1</HHFamilyInsuranceSysKey>
                                  <DeclinedInd tc="0">False</DeclinedInd>
                                  <LineOfBusiness tc="3">Disability Insurance</LineOfBusiness>
                             </HHFamilyInsurance>
                             <HHFamilyInsurance>
                                  <HHFamilyInsuranceSysKey>1</HHFamilyInsuranceSysKey>
                                  <DeclinedInd tc="0">False</DeclinedInd>
                                  <LineOfBusiness tc="5">LTC Insurance</LineOfBusiness>
                             </HHFamilyInsurance>
                             <FinancialExperience>
                                  <InvestmentType tc="7">CD</InvestmentType>
                                  <YearsOfInvestmentExperience>1</YearsOfInvestmentExperience>
                                  <OLifEExtension VendorCode="05" ExtensionCode="FinancialExperience">
                                       <FinancialExperienceExtension>
                                            <AssetValue>30000</AssetValue>
                                       </FinancialExperienceExtension>
                                  </OLifEExtension>
                             </FinancialExperience>
                             <FinancialExperience>
                                  <InvestmentType tc="3">Stock</InvestmentType>
                                  <YearsOfInvestmentExperience>1</YearsOfInvestmentExperience>
                                  <OLifEExtension VendorCode="05" ExtensionCode="FinancialExperience">
                                       <FinancialExperienceExtension>
                                            <AssetValue>5000</AssetValue>
                                       </FinancialExperienceExtension>
                                  </OLifEExtension>
                             </FinancialExperience>
                             <FinancialExperience>
                                  <InvestmentType tc="2">Bond</InvestmentType>
                                  <YearsOfInvestmentExperience>6</YearsOfInvestmentExperience>
                                  <OLifEExtension VendorCode="05" ExtensionCode="FinancialExperience">
                                       <FinancialExperienceExtension>
                                            <AssetValue>50000</AssetValue>
                                       </FinancialExperienceExtension>
                                  </OLifEExtension>
                             </FinancialExperience>
                             <FinancialExperience>
                                  <InvestmentType tc="15">Variable Annuities</InvestmentType>
                                  <YearsOfInvestmentExperience>4</YearsOfInvestmentExperience>
                                  <OLifEExtension VendorCode="05" ExtensionCode="FinancialExperience">
                                       <FinancialExperienceExtension>
                                            <AssetValue>50000</AssetValue>
                                       </FinancialExperienceExtension>
                                  </OLifEExtension>
                             </FinancialExperience>
                             <FinancialExperience>
                                  <InvestmentType tc="6">Mutual Funds</InvestmentType>
                                  <YearsOfInvestmentExperience>0</YearsOfInvestmentExperience>
                                  <OLifEExtension VendorCode="05" ExtensionCode="FinancialExperience">
                                       <FinancialExperienceExtension>
                                            <AssetValue>0</AssetValue>
                                       </FinancialExperienceExtension>
                                  </OLifEExtension>
                             </FinancialExperience>
                             <FinancialExperience>
                                  <InvestmentType tc="1009800001">Cash</InvestmentType>
                                  <YearsOfInvestmentExperience>20</YearsOfInvestmentExperience>
                                  <OLifEExtension VendorCode="05" ExtensionCode="FinancialExperience">
                                       <FinancialExperienceExtension>
                                            <AssetValue>100000</AssetValue>
                                       </FinancialExperienceExtension>
                                  </OLifEExtension>
                             </FinancialExperience>
                             <FinancialExperience>
                                  <InvestmentType tc="2147483647">Other</InvestmentType>
                                  <YearsOfInvestmentExperience>0</YearsOfInvestmentExperience>
                                  <OLifEExtension VendorCode="05" ExtensionCode="FinancialExperience">
                                       <FinancialExperienceExtension>
                                            <AssetValue>0</AssetValue>
                                       </FinancialExperienceExtension>
                                  </OLifEExtension>
                             </FinancialExperience>
                        </Risk>
                        <Employment EmployerPartyID="Party4">
                             <OccupClass tc="1009800001">Employed</OccupClass>
                             <Occupation>Solution Architect</Occupation>
                             <EmployerName>AXA</EmployerName>
                             <YearsAtEmployment>15</YearsAtEmployment>
                        </Employment>
                        <GovtIDInfo>
                             <GovtID>123456789</GovtID>
                             <GovtIDTC tc="17">Passport</GovtIDTC>
                             <GovtIDExpDate>2015-08-24</GovtIDExpDate>
                             <Nation tc="1">USA</Nation>
                             <Jurisdiction tc="35">New Jersey</Jurisdiction>
                        </GovtIDInfo>
                   </Party>
                   <Party id="Party2">
                        <PartyTypeCode tc="1">Person</PartyTypeCode>
                        <PartySysKey>ProfileID456</PartySysKey>
                        <Person>
                             <FirstName>Jacqueline</FirstName>
                             <LastName>Doe</LastName>
                             <MarStat tc="1">Married</MarStat>
                             <Gender tc="2">Female</Gender>
                             <BirthDate>1975-05-07</BirthDate>
                             <EducationType tc="3">Associate Degree</EducationType>
                             <Citizenship tc="1">USA</Citizenship>
                             <DriversLicenseNum>D987654321</DriversLicenseNum>
                             <DriversLicenseState tc="35">New Jersey</DriversLicenseState>
                             <ImmigrationStatus tc="8">Citizen</ImmigrationStatus>
                             <DriversLicenseExpDate>2012-05-25</DriversLicenseExpDate>
                             <OLifEExtension VendorCode="05" ExtensionCode="Person">
                                  <PersonExtension>
                                       <NoDriversLicenseInd tc="0">False</NoDriversLicenseInd>
                                  </PersonExtension>
                             </OLifEExtension>
                        </Person>
                        <Address>
                             <Line1>125 Finn Lane</Line1>
                             <City>North Brunswick</City>
                             <AddressStateTC tc="35">New Jersey</AddressStateTC>
                             <Zip>08902</Zip>
                        </Address>
                        <Phone>
                             <PhoneTypeCode tc="1">Home</PhoneTypeCode>
                             <DialNumber>732456789</DialNumber>
                        </Phone>
                        <Risk>
                             <HHFamilyInsurance>
                                  <HHFamilyInsuranceSysKey>1</HHFamilyInsuranceSysKey>
                                  <DeclinedInd tc="0">False</DeclinedInd>
                                  <LineOfBusiness tc="1">Life Insurance</LineOfBusiness>
                             </HHFamilyInsurance>
                        </Risk>
                        <Employment>
                             <OccupClass tc="4">Unemployed</OccupClass>
                        </Employment>
                        <GovtIDInfo>
                             <GovtID>987654321</GovtID>
                             <GovtIDTC tc="17">Passport</GovtIDTC>
                             <GovtIDExpDate>2015-08-24</GovtIDExpDate>
                             <Nation tc="1">USA</Nation>
                             <Jurisdiction tc="35">New Jersey</Jurisdiction>
                        </GovtIDInfo>
                   </Party>
                   <Party id="Party3">
                        <PartyTypeCode tc="1">Person</PartyTypeCode>
                        <Person>
                             <FirstName>Joe</FirstName>
                             <LastName>Doe</LastName>
                             <Age>15</Age>
                        </Person>
                   </Party>
                   <Party id="Party4">
                        <Person/>
                        <Address>
                             <Line1>425 Washington Blvd.</Line1>
                             <City>Jersey City</City>
                             <AddressStateTC tc="35">New Jersey</AddressStateTC>
                             <Zip>07302</Zip>
                        </Address>
                   </Party>
                   <Relation OriginatingObjectID="Grouping1" id="Relation1" RelatedObjectID="Party1">
                        <OriginatingObjectType tc="16">Grouping</OriginatingObjectType>
                        <RelatedObjectType tc="6">Party</RelatedObjectType>
                        <RelationRoleCode tc="30">Member</RelationRoleCode>
                   </Relation>
                   <Relation OriginatingObjectID="Grouping1" id="Relation2" RelatedObjectID="Party2">
                        <OriginatingObjectType tc="16">Grouping</OriginatingObjectType>
                        <RelatedObjectType tc="6">Party</RelatedObjectType>
                        <RelationRoleCode tc="30">Member</RelationRoleCode>
                   </Relation>
                   <Relation OriginatingObjectID="Party1" id="Relation3" RelatedObjectID="Party3">
                        <OriginatingObjectType tc="6">Party</OriginatingObjectType>
                        <RelatedObjectType tc="6">Party</RelatedObjectType>
                        <RelationRoleCode tc="40">Dependant</RelationRoleCode>
                   </Relation>
                   <Relation OriginatingObjectID="Holding1" id="Relation4" RelatedObjectID="Party1">
                        <OriginatingObjectType tc="4">Holding</OriginatingObjectType>
                        <RelatedObjectType tc="6">Party</RelatedObjectType>
                        <RelationRoleCode tc="8">Owner</RelationRoleCode>
                   </Relation>
                   <Relation OriginatingObjectID="Holding1" id="Relation5" RelatedObjectID="Party2">
                        <OriginatingObjectType tc="4">Holding</OriginatingObjectType>
                        <RelatedObjectType tc="6">Party</RelatedObjectType>
                        <RelationRoleCode tc="184">Joint Owner</RelationRoleCode>
                   </Relation>
                   <Relation OriginatingObjectID="Form1" id="Relation6" RelatedObjectID="Party1">
                        <OriginatingObjectType tc="101">FormInstance</OriginatingObjectType>
                        <RelatedObjectType tc="6">Party</RelatedObjectType>
                        <RelationRoleCode tc="107">Form For</RelationRoleCode>
                   </Relation>
                   <FormInstance id="Form1">
                        <FormResponse>
                             <ResponseText>No</ResponseText>
                             <QuestionType tc="1009800001">Is the Client/Owner with an interest in the account either: (A) a senior military, governmental, or political official in a non-U.S. country, or (B) closely associated with or an immediate family member of such official?</QuestionType>
                        </FormResponse>
                        <FormResponse>
                             <ResponseText>Yes</ResponseText>
                             <QuestionType tc="1009800005">I am familiar with the product(s) being sold and have determined proper suitability. For deferred variable annuity purchases only: I have reasonable grounds for believing that the recommendations for this customer to purchase/exchange an annuity is suitable on the basis of the facts disclosed by the customer as to his/her investments, insurance products and financial situation and needs.</QuestionType>
                        </FormResponse>
                   </FormInstance>
              </OLifE>
         </TXLifeRequest>
    </TXLife>');
    /

    It's a really bad idea to assemble XML using strings and string concatenation in SQL or PL/SQL. First there is a 4K limit in SQL, and 32K limit in PL/SQL, which means you end up constructing the XML in chunks, adding uneccessary complications. 2nd you cannot confirm the XML is valid or well formed using external tools.
    IMHO it makes much more sense to keep the XML content seperated from the SQL / PL/SQL code
    When the XML can be stored a File System accessable from the database, The files can be loaded into the database using mechansims like BFILE.
    In cases where the XML must be staged on a remote file system, the files can be loaded into the database using FTP or HTTP and in cases where this is not an option, SQLLDR.
    -Mark

  • XMLType and CLOB

    For full document retrieval and inserts is there a performance difference between declaring a XMLType or a simple CLOB database column type in table.
    Thanks in advance.

    I have a related question:
    Is there any difference between using the XMLTYPE constructor function and using XMLTYPE.CREATEXML to convert a temporary CLOB to XMLTYPE?
    I have the following in a PL/SQL function (simplified):
    FUNCTION get_geocode_xml( p_geocodes IN CLOB) RETURN XMLTYPE IS
      r_geocodes XMLTYPE;
    BEGIN
      r_geocodes := XMLTYPE.CREATEXML(p_geocodes);
      RETURN r_geocodes;
    END;Is this the same as using the constructor as in
    r_geocodes := XMLTYPE(p_geocodes);
    It seems to work either way, but I've only extensively tested the first method.

  • Trying to convert a CLOB to an XMLTYPE

    I'm trying to insert a xm ldocument stored in a CLOB into a XMLTYPE column registered to a schema.
    I'm trying so use the function below to convert the CLOB to an XMLTYPEbut i keep getting a ORA-06553 Error: wrong number or arguments. Am i using the xmltype constructor properly?
    create or replace function to_xmltype (clobcol CLOB)
    return xmltype as
    begin
    return xmltype(clobcol,'http://localhost:8080/source/schemas/poSource/xsd/mySchema.xsd');
    end;
    insert into xml_table (xmldata) values (select to_xmltype(ct.clob_data) from clob_table ct );
    Thanks for the help

    Looks fine to me except that you should omit the values clause:
    insert into xml_table (xmldata) select to_xmltype(ct.clob_data) from clob_table ct ;

  • Replace xml code when used as a xmltype converted from clob.

    I am still new at all this so I will try to make sense.
    I have the "sys_xmlgen" where it takes my clob_content which is a clob and converts it into the v_xml which is xmltype.
    ****code to show change of clob to xmltype.
    SELECT sys_xmlgen(clob_content) INTO v_xml FROM xmltest2 WHERE item_id = v_item_id;
    update xmltest2 set xml = v_xml where item_id = v_item_id;
    **end of code
    When you use sys_xmlgen it changes the xml into this example:
    <?xml version="1.0"?>
    <CLOB_CONTENT>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
    &lt;!DOCTYPE metadata SYSTEM &quot;csdgm2.dtd&quot;&gt;
    &lt;?xml-stylesheet href=&quot;FGDC_V2.xsl&quot; type=&quot;text/xsl&quot;?&gt;
    &lt;metadata&gt;
    &lt;idinfo&gt;
    </CLOB_CONTENT>
    I need to remove the <CLOB_CONTENT> tag and change some things such as the "&lt;" to a "<" and so on. But when I do a replace statement
    select replace(clob_content, '&lt;', '<') into v_xml from xmltest2;
    It says I can not do a clob into number.
    Just to make myself clear, the clob_content is clob and v_xml is xmltype. SOOO I think that is where my problem is. Does anyone know the syntax to replace the code in my xml so that it looks like the original clob xml??
    Any help would be appreciated.

    I am still new at all this so I will try to make sense.
    I have the "sys_xmlgen" where it takes my clob_content which is a clob and converts it into the v_xml which is xmltype.
    ****code to show change of clob to xmltype.
    SELECT sys_xmlgen(clob_content) INTO v_xml FROM xmltest2 WHERE item_id = v_item_id;
    update xmltest2 set xml = v_xml where item_id = v_item_id;
    **end of code
    When you use sys_xmlgen it changes the xml into this example:
    ?xml version="1.0"?>
    <CLOB_CONTENT>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
    &lt;!DOCTYPE metadata SYSTEM &quot;csdgm2.dtd&quot;&gt;
    &lt;?xml-stylesheet href=&quot;FGDC_V2.xsl&quot; type=&quot;text/xsl&quot;?&gt;
    &lt;metadata&gt;
    &lt;idinfo&gt;
    &lt;citation&gt;
    &lt;citeinfo&gt;</CLOB_CONTENT>
    I need to remove the <CLOB_CONTENT> tag and change some things such as the "<" to a "<" and so on. But when I do a replace statement
    select replace(clob_content, '<', '<') into v_xml from xmltest2;
    It says I can not do a clob into number.
    Just to make myself clear, the clob_content is clob and v_xml is xmltype. SOOO I think that is where my problem is. Does anyone know the syntax to replace the code in my xml so that it looks like the original clob xml??
    Any help would be appreciated.

  • How to convert XMLTYPE data into CLOB without using getclobval()

    Please tell me how to convert data which is stored in the table in XMLTYPE column to a CLOB.
    When i use getClobVal(), i get an error. So please tell me some other option except getClobVal()

    CREATE OR REPLACE PACKAGE BODY CONVERT_XML_TO_HTML AS
         FUNCTION GENERATE_HTML(TABLE_NAME VARCHAR2, FILE_NAME VARCHAR2, STYLESHEET_QUERY VARCHAR2, WHERE_CLAUSE VARCHAR2, ORDERBY_CLAUSE VARCHAR2) RETURN CLOB IS
         lHTMLOutput XMLType;
         lXSL CLOB;
              lXMLData XMLType;
              FILEID UTL_FILE.FILE_TYPE;
              HTML_RESULT CLOB;
              SQL_QUERY VARCHAR2(300);
              WHERE_QUERY VARCHAR2(200);
              fileDirectory VARCHAR2(100);
              slashPosition NUMBER;
              actual_fileName VARCHAR2(100);
              XML_HTML_REF_CUR_PT XML_HTML_REF_CUR;
              BEGIN
                   IF WHERE_CLAUSE IS NOT NULL AND ORDERBY_CLAUSE IS NOT NULL THEN
                   SQL_QUERY := 'SELECT * FROM ' || TABLE_NAME ||' WHERE ' || WHERE_CLAUSE || ' ORDER BY ' || ORDERBY_CLAUSE;
                        ELSE IF WHERE_CLAUSE IS NOT NULL AND ORDERBY_CLAUSE IS NULL THEN
                             SQL_QUERY := 'SELECT * FROM ' || TABLE_NAME || ' WHERE ' || WHERE_CLAUSE;
                             ELSE IF WHERE_CLAUSE IS NULL AND ORDERBY_CLAUSE IS NOT NULL THEN
                                  SQL_QUERY := 'SELECT * FROM ' || TABLE_NAME || ' ORDER BY ' || ORDERBY_CLAUSE;
                                  ELSE IF WHERE_CLAUSE IS NULL AND ORDERBY_CLAUSE IS NULL THEN
                                  SQL_QUERY := 'SELECT * FROM ' || TABLE_NAME;
                   END IF;
                        END IF;
                             END IF;
                                  END IF;
                   OPEN XML_HTML_REF_CUR_PT FOR SQL_QUERY;
              lXMLData := GENERATE_XML(XML_HTML_REF_CUR_PT);
                   --lXSL := GET_STYLESHEET(STYLESHEET_QUERY);
                                  if(lXMLData is not null) then
                                  dbms_output.put_line('lXMLData pass');
                                  else
                                            dbms_output.put_line('lXMLData fail');
                   end if;
                   lHTMLOutput := lXMLData.transform(XMLType(STYLESHEET_QUERY));
                   --INSERT INTO TEMP_CLOB_TAB2 VALUES(CLOB(lHTMLOutput));
                   if(lHTMLOutput is not null) then
                                  dbms_output.put_line('lHTMLOutput pass');
                                  else
                                            dbms_output.put_line('lHTMLOutput fail');
                   end if;
                   HTML_RESULT := lHTMLOutput.getclobVal();
                   if(HTML_RESULT is not null) then
                                  dbms_output.put_line('HTML_RESULT pass'||HTML_RESULT);
                                  else
                                            dbms_output.put_line('HTML_RESULT fail');
                   end if;
                   -- If the filename has been supplied ...
         IF FILE_NAME IS NOT NULL THEN
    -- locate the final '/' or '\' in the pathname ...
         slashPosition := INSTR(FILE_NAME, '/', -1 );
         IF slashPosition = 0 THEN
         slashPosition := INSTR(FILE_NAME,'\', -1 );
         END IF;
    -- separate the filename from the directory name ...
         fileDirectory := SUBSTR(FILE_NAME, 1,slashPosition - 1 );
         actual_fileName := SUBSTR(FILE_NAME, slashPosition + 1 );
                   END IF;
                        DBMS_OUTPUT.PUT_LINE(fileDirectory||' ' ||actual_fileName);
                   FILEID := UTL_FILE.FOPEN(fileDirectory,actual_fileName, 'W');
                   UTL_FILE.PUT_LINE(FILEID, '<title> hi </title>');
              UTL_FILE.PUT_LINE(FILEID, HTML_RESULT);
                   UTL_FILE.FCLOSE (FILEID);
    DBMS_OUTPUT.PUT_LINE('CLOB SIZE'||DBMS_LOB.GETLENGTH(HTML_RESULT));               
                   RETURN HTML_RESULT;
                   --RETURN lHTMLOutput;
              EXCEPTION
                        WHEN OTHERS
                             THEN DBMS_OUTPUT.PUT_LINE('ERROR!!!!!!!!!!!!');
              END GENERATE_HTML;
         FUNCTION GENERATE_XML(XML_HTML_REF_CUR_PT XML_HTML_REF_CUR) RETURN XMLType IS
              qryCtx DBMS_XMLGEN.ctxHandle;
              result CLOB;
              result1 xmltype;
              BEGIN
                   qryCtx := DBMS_XMLGEN.newContext(XML_HTML_REF_CUR_PT);
                   result := DBMS_XMLGEN.getXML(qryCtx);
                   --dbms_output.put_line(result);
                   result1 := xmltype(result);
                   INSERT INTO temp_clob VALUES(result);
                   if(result1 is not null) then
                                  dbms_output.put_line('pass');
                                  else
                                            dbms_output.put_line('fail');
                   end if;
                        return result1;
                        DBMS_XMLGEN.closeContext(qryCtx);
         END GENERATE_XML;     
    END CONVERT_XML_TO_HTML;
    This is the code which i am using to generate the XML and subsequently to generate the HTML output out of that using a XSL stylesheet.
    The error is Numeric or value error..

  • XMLType.extract cannot show special French characters in select statement

    Hi,
    The (e acute) é characters get garbled when they are retrieved from the
    XMLType column of a regular table.
    How can we fix to get (e acute) é characters properly?
    We both tried setting "setenv NLS_LANG French_France.WE8ISO8859P1" and
    "setenv NLS_LANG French_France.WE8DEC" before loading the table.
    Database version:
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE    11.2.0.2.0      Production
    TNS for Linux: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - ProductionThe sample test case is as follows:
    --connect to any schema where you can store XMLType
    set long 2000;
    set pagesize 2000;
    set serveroutput on;
    --delete from test;
    drop table test;
    create table test (id number, xmldata XMLType);
    declare
    featureDescriptorXML  CLOB;
    xml_type XMLType;
    new_xml_type XMLType;
    myName varchar2(100);
    myName2 varchar2(100);
    myName3 varchar2(100);
    stmt varchar2(4000);
    begin
    featureDescriptorXML :=
    '<?xml version="1.0" encoding="UTF-8"?>' ||
    '<abc:TheFeature xmlns:' || 'de' || '="' || 'http://abc.klmno.org/fghde' || '" xmlns:abc="http://www.ghijklmn.net/abc"' ||
    ' xmlns:xyz="http://www.ghijklmn.net/xyz">' ||
    '<abc:Name>de:MyGénérique</abc:Name>' ||
    '</abc:TheFeature>';
    xml_type := xmltype(featureDescriptorXML);
    myName := xml_type.extract('/abc:TheFeature/abc:Name/text()', 'xmlns:abc="http://www.ghijklmn.net/abc"').getStringVal();
    dbms_output.put_line('abc:Name value stored in VARCHAR2 variable from XMLType variable is ' || myName);
    -- can show French chars
    insert into test(id, xmldata) values(20, xml_type);
    stmt := 'select t.xmldata.extract(''/abc:TheFeature/abc:Name/text()'', ''xmlns:abc="http://www.ghijklmn.net/abc"'').getStringVal() from test t';
    execute immediate stmt into myName2;
    dbms_output.put_line('abc:Name value stored in VARCHAR2 variable from XMLType column in 2nd version is ' || myName2);
    -- cannot show French chars
    stmt := 'select  t.xmldata from test t';
    execute immediate stmt into new_xml_type;
    myName3 := new_xml_type.extract('/abc:TheFeature/abc:Name/text()', 'xmlns:abc="http://www.ghijklmn.net/abc"').getStringVal();
    dbms_output.put_line('abc:Name value stored in VARCHAR2 variable from first XMLType column and then from XMLType variable in 3rd version is ' || myName3);
    -- cannot show French chars
    end;
    select t.xmldata.extract('/abc:TheFeature/abc:Name/text()', 'xmlns:abc="http://www.ghijklmn.net/abc"').getStringVal()
    from test t;
    -- Cannot show French chars
    select t.xmldata.extract('/abc:TheFeature/abc:Name/text()', 'xmlns:abc="http://www.ghijklmn.net/abc"').getStringVal() "myname"
    from test t;
    -- Cannot show French chars
    select t.xmldata.getCLOBVal() from test t;
    -- Cannot show French chars
    select t.xmldata from test t;
    -- Can show French charsOutput is as follows with setenv NLS_LANG French_France.WE8ISO8859P1
    and NLS_DATABASE_PARAMETERS are as follows:
    SQL> select * from nls_database_parameters;
    PARAMETER                      VALUE
    NLS_LANGUAGE                   AMERICAN
    NLS_TERRITORY                  AMERICA
    NLS_CURRENCY                   $
    NLS_ISO_CURRENCY               AMERICA
    NLS_NUMERIC_CHARACTERS         .,
    NLS_CHARACTERSET               WE8DEC
    NLS_CALENDAR                   GREGORIAN
    NLS_DATE_FORMAT                DD-MON-RR
    NLS_DATE_LANGUAGE              AMERICAN
    NLS_SORT                       BINARY
    NLS_TIME_FORMAT                HH.MI.SSXFF AM
    PARAMETER                      VALUE
    NLS_TIMESTAMP_FORMAT           DD-MON-RR HH.MI.SSXFF AM
    NLS_TIME_TZ_FORMAT             HH.MI.SSXFF AM TZR
    NLS_TIMESTAMP_TZ_FORMAT        DD-MON-RR HH.MI.SSXFF AM TZR
    NLS_DUAL_CURRENCY              $
    NLS_COMP                       BINARY
    NLS_LENGTH_SEMANTICS           BYTE
    NLS_NCHAR_CONV_EXCP            FALSE
    NLS_NCHAR_CHARACTERSET         AL16UTF16
    NLS_RDBMS_VERSION              11.2.0.2.0
    20 ligne(s) sélectionnée(s).
    Table creé.
    abc:Name value stored in VARCHAR2 variable from XMLType variable is
    de:MyGénérique
    abc:Name value stored in VARCHAR2 variable from XMLType column in 2nd version is
    de:MyGénérique
    abc:Name value stored in VARCHAR2 variable from first XMLType column and then
    from XMLType variable in 3rd version is de:MyGénérique
    Procdure PL/SQL terminée avec succès.
    T.XMLDATA.EXTRACT('/ABC:THEFEATURE/ABC:NAME/TEXT()','XMLNS:ABC="HTTP://WWW.GHIJK
    de:MyGénérique
    myname
    de:MyGénérique
    T.XMLDATA.GETCLOBVAL()
    <?xml version="1.0" encoding="DEC-MCS"?>
    <abc:TheFeature xmlns:de="http://abc.klmno.org/fghde" xmlns:abc="http://www.ghij
    klmn.net/abc" xmlns:xyz="http://www.ghijklmn.net/xyz">
      <abc:Name>de:MyGénérique</abc:Name>
    </abc:TheFeature>
    XMLDATA
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <abc:TheFeature xmlns:de="http://abc.klmno.org/fghde" xmlns:abc="http://www.ghij
    klmn.net/abc" xmlns:xyz="http://www.ghijklmn.net/xyz">
      <abc:Name>de:MyGénérique</abc:Name>
    </abc:TheFeature>We also tried setting NLS_CHARACTERSET to AL32UTF8
    via ALTER DATABASE CHARACTER SET,
    and then shutting down the database and restarting it.
    But, that did not help.
    Thanks

    Good to hear then, you have not yet got a SR on your hands.
    One of the reasons I hate NLS issues is that me first one had to do with an client browser/ application server and database setup that involved not equal settings between the app.server and the database. Always, always fully check that the app.server (on all fronts) have the same NLS settings as the database so that you avoid unnecessary conversion between the middle tier and the database tier. "On all fronts" means, as I once painfully discovered, possible NLS settings in a registry, app.server configuration file, java application in the JVM, etc, etc, etc. Another issue is that JDBC drivers, AFAIK, have issues with "opaque data types" (http://en.wikipedia.org/wiki/Opaque_data_type) like "XMLTYPE" so, to be sure, I would advice to transport the "XML content" in a data type which is supported much longer like "CLOB". In such cases, NLS conversions shouldn't take place. There are exceptions of course, one I can think of right now is when you move Binary XML content via the binary xml transport method (can't remember right now the proper java classes to use for this) between the client and server to obtain performance gains due to among others less and more efficient data transport across the network and avoiding validation and post parse overhead during the Binary XML content handling in the database.
    Looked it up anyway :-) the following is part of the 11.2 Oracle XDK
    Binary XML usage with Java:
    http://download.oracle.com/docs/cd/E14072_01/appdev.112/e10708/adx_j_xmlbin.htm#BAJFBGGB
    Scalable DOM:
    http://download.oracle.com/docs/cd/E14072_01/appdev.112/e10708/adx_j_parser.htm#CCHGIADJ

  • Architecture Advice - XMLTYPE, VPD, PL

    Hi, apologies if this is off-topic but wasn't sure which forum to pick for general architecture questions...
    I've inherited an existing application architecture that we're struggling to scale beyond about 100 concurrent users on small-scale hardware, and would appreciate any advice.
    It is a 3-tier web application, using XMLTYPE (CLOB), VPD and with the vast majority of the business logic and workflow coded in PL/SQL.
    We're experiencing that the CLOB-based XMLTYPE columns very quickly eat up all available CPU, and our very complex VPD policies tends to slow tables down about 300% above a few thousand rows. Since the data is directly updated in PL/SQL our middle tier (java) can't cache anything.
    The expectation is that this architecture should scale to thousands of concurrent users, with reasonablly large data volumes, on relatively small scale (e.g. 2 or 4 CPU) h/w. Our market cannot really afford/have the expertise to use additional Oracle products such as Grid, Partitioning, RAC etc.
    I'm not sure where to start - we've tried tuning individual queries but I think we'll need more than that. We're using the latest edition of 10g RDBMS.

    I've used a temporary table the way you propose, and it works pretty well. I override a method of my View Object (executeQuery, I think) to call some PL/SQL to load the temporary table before executing the query. Performance is not quite as good, but isn't a show stopper. My particular application was using a read-only VO, with no underlying Entity Object, but I think you could override an EO method to call some PL/SQL to use data from the temporary table to update the real tables.
    I've looked at the original version of Avrom Roy-Faderman's framework extension, but I know he substantially revised it since I looked. It is a cool use of the extensible nature of the ADF BC framework. Avrom has placed the framework in samplecode.oracle.com, and now someone else is leading the project.
    This should work well for PL/SQL APIs that have only database native types as parameters to the procedures. But it has the same problems as I mentioned before with PL/SQL records and collections, unless you first make them into database object types with CREATE TYPE.
    I have also used the JPublisher interface of JDev. This is pretty neat and it can do the CREATE TYPE commands for you and write conversions to and from PL/SQL types. It also generates A LOT of Java code - the problem with it is that as a code generator it has to generate much more code than you would if you wrote it by hand to handle cases that you know won't occur with your data. And the code it writes can be hard to read and maintain. The classes it writes can be integrated into ADF BC objects, but it still is going to need some hand coding to do the job. Or some people abandon ADF BC, and use these as POJOs which can be made into Data Controls.

  • Unable to convert BLOB to XML using XMLTYPE

    Hello (XML) Experts
    I need your help with manipulating a BLOB column containing XML data - I am encountering the following error:
    ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00200: could not convert from encoding UTF-8 to WINDOWS-1252
    Error at line 1
    ORA-06512: at "SYS.XMLTYPE", line 283
    I am on Windows 7 64 bit, Oracle 11.2.0.3 64 bit and database character set is WE8MSWIN1252, NLS_LANG is set to AMERICAN_AMERICA.AL32UTF8. The BLOB column contains the following XML data:
    <?xml version="1.0" encoding="utf-8"?>
    <Root CRC="-4065505">
      <Header Converted="0">
        <Version Type="String" Value="512" />
        <Revision Type="String" Value="29" />
        <SunSystemsVersion Type="String" Value="" />
        <Date Type="String" Value="20080724" />
        <Time Type="String" Value="165953" />
        <DAG Type="String" Value="" />
        <ChkID Type="String" Value="" />
        <FormType Type="String" Value="1" />
        <DB Type="String" Value="AllBusinessUnits" />
        <FuncID Type="String" Value="SOE" />
        <Status Type="String" Value="" />
        <FileType Type="String" Value="SFL" />
        <Descriptions>
          <Default Type="String" Value="Sales Order Entry" />
          <L01 Type="String" Value="Sales Order Entry" />
          <L33 Type="String" Value="Saisie commande client" />
          <L34 Type="String" Value="Entrada de órdenes de venta" />
          <L39 Type="String" Value="Inserimento ordine di vendita" />
          <L49 Type="String" Value="Aufträge erfassen" />
          <L55 Type="String" Value="Entrada de pedido de venda" />
          <L81 Type="String" Value="å?—注オーダー入力" />
          <L86 Type="String" Value="销售订å?•å½•å…¥" />
          <L87 Type="String" Value="銷售訂單錄入" />
        </Descriptions>
      </Header>
    <FormDesignerAppVer Type="String" Value="5.1" SFLOnly="1" />
    </Root>I am using the XMLTYPE constructor and passing in the BLOB column and the character set id of the XML data stored in the BLOB column in order to extract and update a node in the XML as follows:
    select xmltype(srce_form_detail,873) from SRCE_FORM where 873 above corresponds to the utf-8 encoding of the XML data in the BLOB column i.e. AL32UTF8, but this results in the above error.
    I have also tried converting the BLOB to a CLOB first as below where BLOB2CLOB is a function that converts the BLOB to a CLOB:
    select xmltype(BLOB2CLOB(srce_form_detail)).EXTRACT('/Root/Header/DB').getStringVal() XMLSrc  from SRCE_FORM;This results in the following error:
    ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00210: expected '<' instead of '¿'
    Error at line 1
    ORA-06512: at "SYS.XMLTYPE", line 272
    ORA-06512: at line 1
    Looking at the XML in the BLOB I noticed that it contains a BOM(byte order mark) and this is causing the XML parsing to fail and I don't know how to deal with it and I don't want to simply SUBSTR it out.
    What I am trying to achieve is to extract the contents of the DB node in the XML and depending on its value I need to update the 'Value' part of that node. I am stuck at the point of extracting the contents of the DB node.
    I hope I have provided enough information and I would appreciate any suggestions on how best to resolve this - my XML knowledge is very limited so I would appreciate any help.
    Regards,
    Mohinder

    Hi Marc
    Thanks for your response.
    You are correct that the blob contains Japanese and Chinese characters but I was expecting that using the XMLTYPE constructor would convert the character set albeit with some data loss or then not display the Chinese and Japanese characters correctly.
    It seems to me that XMLTYPE is not handling/interpreting the BOM contained in the BLOB since even converting the BLOB to CLOB is resulting in an error. If I use SUBSTR and ignore the BOM to extract the XML from the BLOB then it works and as expected the Chinese and Japanese characters are not displayed correctly, they are displayed as '¿' corresponding to the lines beginning with L81, L86 & L87 , see below:
    select xmltype(SUBSTR(BLOB2CLOB(srce_form_detail),4)) from SRCE_FORM
    <?xml version="1.0" encoding="utf-8"?>
    <Root CRC="-4065505">
      <Header Converted="0">
        <Version Type="String" Value="512" />
        <Revision Type="String" Value="29" />
        <SunSystemsVersion Type="String" Value="" />
        <Date Type="String" Value="20080724" />
        <Time Type="String" Value="165953" />
        <DAG Type="String" Value="" />
        <ChkID Type="String" Value="" />
        <FormType Type="String" Value="1" />
        <DB Type="String" Value="AllBusinessUnits" />
        <FuncID Type="String" Value="SOE" />
        <Status Type="String" Value="" />
        <FileType Type="String" Value="SFL" />
        <Descriptions>
          <Default Type="String" Value="Sales Order Entry" />
          <L01 Type="String" Value="Sales Order Entry" />
          <L33 Type="String" Value="Saisie commande client" />
          <L34 Type="String" Value="Entrada de ¿¿rdenes de venta" />
          <L39 Type="String" Value="Inserimento ordine di vendita" />
          <L49 Type="String" Value="Auftr¿¿ge erfassen" />
          <L55 Type="String" Value="Entrada de pedido de venda" />
          <L81 Type="String" Value="¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿" />
          <L86 Type="String" Value="¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿" />
          <L87 Type="String" Value="¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿" />
        </Descriptions>
      </Header>Can you please let me know how I can extract the binary dump of the BLOB and post it on the forum as I don't know how to do this. Below is snippet of the hexadecimal dump, that includes the BOM. I can post the full hexadecimal dump if this can help you to reproduce the error ?
    EFBBBF3C3F786D6C2076657273696F6E3D22312E302220656E636F64696E673D227574662D38223F3E0D0A3C526F6F74204352433D222D34303635353035223E0D0A20203C48656164657220436F6E7665727465643D2230223E0D0A202020203C56657273696F6E20547970653D22537472696E67222056616C75653D2235313222202F3E0D0A202020203C5265766973696F6E20547970653D22537472696E67222056616C75653D22323922202F3E0D0A202020203C53756E53797374656D7356657273696F6E20547970653D22537472696E67222056616C75653D2222202F3E0D0A202020203C4461746520547970653D22537472696E67222056616C75653D22323030383037323422202F3E0D0A202020203C54696D6520547970653D22537472696E67222056616C75653D2231363539353322202F3E0D0A202020203C44414720547970653D22537472696E67222056616C75653D2222202F3E0D0A202020203C43686B494420547970653D22537472696E67222056616C75653D2222202F3E0D0A202020203C466F726D5479706520547970653D22537472696E67222056616C75653D223122202F3E0D0A202020203C444220547970653D22537472696E67222056616C75653D22416C6C427573696E657373556E69747322202F3E0D0A202020203C46756E63494420547970653D22537472696E67222056616C75653D22534F4522202F3E0D0A202020203C53746174757320547970653D22537472696E67222056616C75653D2222202F3E0D0A202020203C46696C655479706520547970653D22537472696E67222056616C75653D2253464C22202F3E0D0A202020203C4465736372697074696F6E733E0D0A2020202020203C44656661756C7420547970653D22537472696E67222056616C75653D2253616C6573204F7264657220456E74727922202F3E0D0A2020202020203C4C303120547970653D22537472696E67222056616C75653D2253616C6573204F7264657220456E74727922202F3E0D0A2020202020203C4C333320547970653D22537472696E67222056616C75653D2253616973696520636F6D6D616E646520636C69656E7422202F3E0D0A2020202020203C4C333420547970653D22537472696E67222056616C75653D22456E747261646120646520C3B37264656E65732064652076656E746122202F3E0D0A2020202020203C4C333920547970653D22537472696E67222056616C75653D22496E736572696D656E746F206F7264696E652064692076656E6469746122202F3E0D0A2020202020203C4C343920547970653D22537472696E67222056616C75653D224175667472C3A4676520657266617373656E22202F3E0D0A2020202020203C4C353520547970653D22537472696E67222056616C75653D22456E74726164612064652070656469646F2064652076656E646122202F3E0D0A2020202020203C4C383120547970653D22537472696E67222056616C75653D22E58F97E6B3A8E382AAE383BCE38380E383BCE585A5E58A9B22202F3E0D0A2020202020203C4C383620547970653D22537472696E67222056616C75653D22E99480E594AEE8AEA2E58D95E5BD95E585A522202F3E0D0A2020202020203C4C383720547970653D22537472696E67222056616C75653D22E98AB7E594AEE8A882E596AEE98C84E585A522202F3E0D0A202020203C2F4465736372697074696F6E733E0D0A20203C2F4865616465723E0D0A20203C466F726D3E0D0A202020203C4372656174696F6E4C616E6720547970653D22537472696E67222056616C75653D223031222053464C4F6E6C793D223122202F3E0D0A202020203C416374696F6E733E0D0A2020202020203C5065726D697373696F6E73202F3E0D0A202020203C2F416374696F6E733E0D0A202020203C48656C70202F3E0D0A202020203C466F6E743E0D0A2020202020203C446566466F6E7453697A6520547970653D22496E7465676572222056616C75653D2238222053464C4F6E6C793D223122202F3E0D0A2020202020203C466F6E743E0D0A20202020202020203C4C616E677561676520547970653D22537472696E67222056616C75653D2244656661756C7422202F3E0D0A20202020202020203C466F6E744E616D6520547970653D22537472696E67222056616C75653D224D532053616E7320536572696622202F3E0D0A2020202020203C2F466F6E743E0D0A2020202020203C466F6E743E0D0A20202020202020203C4C616E677561676520547970653D22537472696E67222056616C75653D22383122202F3E0D0A20202020202020203C466F6E744E616D6520547970653D22537472696E67222056616C75653D224D5320554920476F7468696322202F3E0D0A2020202020203C2F466F6E743E0D0A202020203C2F466F6E743E0D0A202020203C436F6E74726F6C733E0D0A2020202020203C436F6E74726F6C3E0D0A20202020202020203C436F6E74726F6C5479706520547970653D22496E746567657222204644496E743D2231222056616C75653D223122202F3E0D0A20202020202020203C446973706C61795479706520547970653D22537472696E6722204644496E743D2230222056616C75653D22466F726D2057696E646F77222053464C4F6E6C793D223122202F3E0D0A20202020202020203C43617074696F6E20547970653D22537472696E6722204644496E743D2230222056616C75653D2253597C3F7C55547C3F7C3F3F3F3F3F3F22202F3E0DThe XML I posted so far is actually truncated as the full XML is quite big but I showed the beginning of it as this is the section I believe that is not being handled properly. Furthermore I am able to write the BLOB out to a file successfully without any errors using DBMS_LOB & UTL_FILE.PUT_RAW and this seems to handle the BOM without any issues but what I really need to do is read a single node in the XML and update it directly preferably using XMLTYPE directly with the BLOB.
    I would welcome your suggestions on how best to read a single node and update it when the XML is contained in a BLOB.
    Regards,
    Mohinder

Maybe you are looking for