XMLElement() returns 'XMLTYPE()'

Hi. I'm a newbie to Oracle XML, and I'm having trouble just getting off the ground. I would expect the following SQL statement:
select xmlelement("dummy",dummy) result from dual;
to return
RESULT
<dummy>X</dummy>
but instead it returns
RESULT()
XMLTYPE()
Any idea why?
I'm running Oracle Database version 10.2.0.2.0 and SQL*Plus version 9.0.1.4.0.
Thank you.

Yes, you are using a version of SQL*PLUS (9.1.x) that is linked with pre 9.2 OCI libraries. These libraries do not understand XMLType. Please make sure that you use SQL*PLUS 9.2.0.3.0 or later. I would strongly recommend that you use a SQL*PLUS version that is equal or newer than your database..
BTW
select xmlelement("dummy",dummy).getCLOBVAL() result from dual
should work as this will series the XML into a CLOB on the server and then send the client a CLOB

Similar Messages

  • Result of function returning XMLType truncated in query

    Oracle 10.2.0.2.0
    myFunc() is a function returning XMLType
    The query:
    select myFunc() from dual;
    return XML about 2Kb
    If I try to run the following query:
    select XMLElement("Test",(myFunc())) from dual;
    then I get a pice of XML with strange symbols at the end (like this L#sП)
    in 9.2.8.0 all works properly. What I should do?

    CREATE TABLE test_data
    (loan_id VARCHAR2(12) NOT NULL,
    workparty_id NUMBER,
    property_id NUMBER,
    contact_id NUMBER,
    primary_flag NUMBER,
    gen_comment VARCHAR2(4000),
    last_updated DATE,
    user_name VARCHAR2(50),
    deleted_flag NUMBER,
    cont_role_id NUMBER,
    contact_person_id NUMBER);
    CREATE TABLE test_data2
    (contact_id NUMBER,
    name VARCHAR2(44));
    INSERT INTO test_data (LOAN_ID,WORKPARTY_ID,PROPERTY_ID,CONTACT_ID,PRIMARY_FLAG,GEN_COMMENT,LAST_UPDATED,USER_NAME,DELETED_FLAG,CONT_ROLE_ID,CONTACT_PERSON_ID)
    VALUES('TEST_L1',10541,12439,11445,1,NULL,TO_DATE('2008-10-17 12:53:32', 'YYYY-MM-DD HH24:MI:SS'),'testuser',0,6,NULL);
    INSERT INTO test_data (LOAN_ID,WORKPARTY_ID,PROPERTY_ID,CONTACT_ID,PRIMARY_FLAG,GEN_COMMENT,LAST_UPDATED,USER_NAME,DELETED_FLAG,CONT_ROLE_ID,CONTACT_PERSON_ID)
    VALUES('TEST_L1',10542,12439,10697,1,NULL,TO_DATE('2008-10-17 12:53:32', 'YYYY-MM-DD HH24:MI:SS'),'testuser',0,2,NULL);
    INSERT INTO test_data (LOAN_ID,WORKPARTY_ID,PROPERTY_ID,CONTACT_ID,PRIMARY_FLAG,GEN_COMMENT,LAST_UPDATED,USER_NAME,DELETED_FLAG,CONT_ROLE_ID,CONTACT_PERSON_ID)
    VALUES('TEST_L1',10543,12439,2070,1,NULL,TO_DATE('2008-10-17 12:53:32', 'YYYY-MM-DD HH24:MI:SS'),'testuser',0,10,NULL);
    INSERT INTO test_data (LOAN_ID,WORKPARTY_ID,PROPERTY_ID,CONTACT_ID,PRIMARY_FLAG,GEN_COMMENT,LAST_UPDATED,USER_NAME,DELETED_FLAG,CONT_ROLE_ID,CONTACT_PERSON_ID)
    VALUES('TEST_L1',10544,12439,2070,1,NULL,TO_DATE('2008-10-17 12:53:32', 'YYYY-MM-DD HH24:MI:SS'),'testuser',0,11,NULL);
    INSERT INTO test_data (LOAN_ID,WORKPARTY_ID,PROPERTY_ID,CONTACT_ID,PRIMARY_FLAG,GEN_COMMENT,LAST_UPDATED,USER_NAME,DELETED_FLAG,CONT_ROLE_ID,CONTACT_PERSON_ID)
    VALUES('TEST_L1',10545,12439,10527,1,NULL,TO_DATE('2008-10-17 12:53:32', 'YYYY-MM-DD HH24:MI:SS'),'testuser',0,19,33512);
    INSERT INTO test_data (LOAN_ID,WORKPARTY_ID,PROPERTY_ID,CONTACT_ID,PRIMARY_FLAG,GEN_COMMENT,LAST_UPDATED,USER_NAME,DELETED_FLAG,CONT_ROLE_ID,CONTACT_PERSON_ID)
    VALUES('TEST_L1',12694,12439,11218,1,NULL,TO_DATE('2008-10-17 12:53:32', 'YYYY-MM-DD HH24:MI:SS'),'testuser',0,20,NULL);
    INSERT INTO test_data (LOAN_ID,WORKPARTY_ID,PROPERTY_ID,CONTACT_ID,PRIMARY_FLAG,GEN_COMMENT,LAST_UPDATED,USER_NAME,DELETED_FLAG,CONT_ROLE_ID,CONTACT_PERSON_ID)
    VALUES('TEST_L1',12695,12439,11219,0,NULL,TO_DATE('2008-10-17 12:53:32', 'YYYY-MM-DD HH24:MI:SS'),'testuser',0,20,NULL);
    INSERT INTO test_data (LOAN_ID,WORKPARTY_ID,PROPERTY_ID,CONTACT_ID,PRIMARY_FLAG,GEN_COMMENT,LAST_UPDATED,USER_NAME,DELETED_FLAG,CONT_ROLE_ID,CONTACT_PERSON_ID)
    VALUES('TEST_L1',12696,12439,11566,0,NULL,TO_DATE('2008-10-17 12:53:32', 'YYYY-MM-DD HH24:MI:SS'),'testuser',0,20,NULL);
    INSERT INTO test_data (LOAN_ID,WORKPARTY_ID,PROPERTY_ID,CONTACT_ID,PRIMARY_FLAG,GEN_COMMENT,LAST_UPDATED,USER_NAME,DELETED_FLAG,CONT_ROLE_ID,CONTACT_PERSON_ID)
    VALUES('TEST_L1',11141,12439,10066,0,NULL,TO_DATE('2008-10-17 12:53:32', 'YYYY-MM-DD HH24:MI:SS'),'testuser',0,7,NULL);
    INSERT INTO test_data (LOAN_ID,WORKPARTY_ID,PROPERTY_ID,CONTACT_ID,PRIMARY_FLAG,GEN_COMMENT,LAST_UPDATED,USER_NAME,DELETED_FLAG,CONT_ROLE_ID,CONTACT_PERSON_ID)
    VALUES('TEST_L1',11142,12439,11215,1,NULL,TO_DATE('2008-10-17 12:53:32', 'YYYY-MM-DD HH24:MI:SS'),'testuser',0,30,NULL);
    INSERT INTO test_data (LOAN_ID,WORKPARTY_ID,PROPERTY_ID,CONTACT_ID,PRIMARY_FLAG,GEN_COMMENT,LAST_UPDATED,USER_NAME,DELETED_FLAG,CONT_ROLE_ID,CONTACT_PERSON_ID)
    VALUES('TEST_L1',11143,12439,11216,1,NULL,TO_DATE('2008-10-17 12:53:32', 'YYYY-MM-DD HH24:MI:SS'),'testuser',0,5,NULL);
    INSERT INTO test_data (LOAN_ID,WORKPARTY_ID,PROPERTY_ID,CONTACT_ID,PRIMARY_FLAG,GEN_COMMENT,LAST_UPDATED,USER_NAME,DELETED_FLAG,CONT_ROLE_ID,CONTACT_PERSON_ID)
    VALUES('TEST_L1',11150,12439,10433,1,NULL,TO_DATE('2008-10-17 12:53:32', 'YYYY-MM-DD HH24:MI:SS'),'testuser',0,3,NULL);
    INSERT INTO test_data (LOAN_ID,WORKPARTY_ID,PROPERTY_ID,CONTACT_ID,PRIMARY_FLAG,GEN_COMMENT,LAST_UPDATED,USER_NAME,DELETED_FLAG,CONT_ROLE_ID,CONTACT_PERSON_ID)
    VALUES('TEST_L1',12307,12439,1984,1,NULL,TO_DATE('2008-10-17 12:53:32', 'YYYY-MM-DD HH24:MI:SS'),'testuser',0,25,NULL);
    INSERT INTO test_data (LOAN_ID,WORKPARTY_ID,PROPERTY_ID,CONTACT_ID,PRIMARY_FLAG,GEN_COMMENT,LAST_UPDATED,USER_NAME,DELETED_FLAG,CONT_ROLE_ID,CONTACT_PERSON_ID)
    VALUES('TEST_L1',23792,12439,11217,1,NULL,TO_DATE('2008-10-17 12:53:32', 'YYYY-MM-DD HH24:MI:SS'),'testuser',0,15,NULL);
    INSERT INTO test_data (LOAN_ID,WORKPARTY_ID,PROPERTY_ID,CONTACT_ID,PRIMARY_FLAG,GEN_COMMENT,LAST_UPDATED,USER_NAME,DELETED_FLAG,CONT_ROLE_ID,CONTACT_PERSON_ID)
    VALUES('TEST_L1',87283,12439,14014,0,NULL,TO_DATE('2008-10-17 12:53:32', 'YYYY-MM-DD HH24:MI:SS'),'testuser',0,32,NULL);
    INSERT INTO test_data2 (CONTACT_ID,NAME)
    VALUES(11218,'11218user');
    INSERT INTO test_data2 (CONTACT_ID,NAME)
    VALUES(10433,'10433user');
    INSERT INTO test_data2 (CONTACT_ID,NAME)
    VALUES(11217,'11217user');
    INSERT INTO test_data2 (CONTACT_ID,NAME)
    VALUES(10066,'10066user');
    INSERT INTO test_data2 (CONTACT_ID,NAME)
    VALUES(14014,'14014user');
    INSERT INTO test_data2 (CONTACT_ID,NAME)
    VALUES(11219,'11219user');
    INSERT INTO test_data2 (CONTACT_ID,NAME)
    VALUES(11566,'11566user');
    INSERT INTO test_data2 (CONTACT_ID,NAME)
    VALUES(11445,'11445user');
    INSERT INTO test_data2 (CONTACT_ID,NAME)
    VALUES(10527,'10527user');
    INSERT INTO test_data2 (CONTACT_ID,NAME)
    VALUES(11215,'11215user');
    INSERT INTO test_data2 (CONTACT_ID,NAME)
    VALUES(10697,'10697user');
    INSERT INTO test_data2 (CONTACT_ID,NAME)
    VALUES(2070,'2070user');
    INSERT INTO test_data2 (CONTACT_ID,NAME)
    VALUES(11216,'11216user');
    INSERT INTO test_data2 (CONTACT_ID,NAME)
    VALUES(1984,'1984user');
    commit;
    create or replace function myFuncXML return xmltype is
    ret xmltype;
    begin
    select
    XMLElement("WorkingParties",
    XMLAgg(
    XMLElement("Items",
    XMLForest(
    wp.workparty_id "ID",
    wp.loan_id "LoanID",
    wp.property_id "PropertyID",
    wp.contact_id "ContactID",
    wp.cont_role_id "ContRoleId",
    null "ParentContactID",
    wp.gen_comment "Description",
    wp.primary_flag "PrimaryFlag"
    ) into ret
    from test_data wp
    where
    nvl(wp.deleted_flag,0) <> 1 and
    wp.property_id = 12439
    and exists (select contact_id from test_data2 where contact_id = wp.contact_id)
    return ret;
    end;
    This sql returns - ok
    select myFuncXML from dual;
    This sql - fail
    select
    XMLElement("Test_root",
    myfuncxml
    from dual;
    if I comment line
    and exists (select contact_id from test_data2 where contact_id = wp.contact_id)
    in function - all works fine

  • Returning XMLType to JSP

    Hello, all.
    I have a stored function that returns XMLType data to a JSP page, similar to the example in the Oracle XML DB Developer's Guide (13-4). My schema was developed with great help from this forum and is referenced here:Re: unique constraint defined in xsd
    My problem is I am getting the following error when I try to access the returned data in the jsp page:
    java.lang.ClassCastException: oracle.sql.OPAQUE
         at querymaps.jspService(querymaps.jsp:45)
    I cannot quite figure out how to get to the returned data.
    Here is the stored function and a sample of data the same select statement returns:
    CREATE OR REPLACE FUNCTION getMaps(userName varchar2)
    RETURN XMLTYPE
    AS
    xmlDoc XMLTYPE;
    BEGIN
    SELECT extract(OBJECT_VALUE, '/mapset/map') into xmlDoc
    FROM mapsetxml
    WHERE existsNode(OBJECT_VALUE,'/mapset['''|| username ||''']')=1;
    RETURN xmlDoc;
    END;
    <map>
    <mapname>Florida</mapname>
    <layer>
    <layername>Counties</layername>
    <layerid>counties</layerid>
    <service>base</service>
    <visible>1</visible>
    <ftype>polygon</ftype>
    </layer>
    <placemark>
    <placename>Florida</placename>
    <envelope>
    <minx>-186185.234572</minx>
    <miny>2709914.999735</miny>
    <maxx>596332.812876</maxx>
    <maxy>3464678.999670</maxy>
    </envelope>
    </placemark>
    </map>
    The JSP scriplet code is nearly right from the sample- I am using a dataSource connection, so I don't know if that is the problem, or not.
    <%
    Connection conn=null;
    CallableStatement stmt = null;
    String dSrcName="jdbc/localDS";
    String userName="tester";
    XMLType xmlRes = null;
    InitialContext ctxt = new InitialContext();
    DataSource ds = (DataSource) ctxt.lookup(dSrcName);
    conn = ds.getConnection();
    try {        
    stmt=conn.prepareCall("{ ? = call getmaps(?)}");
    stmt.registerOutParameter(1, OracleTypes.OPAQUE,"SYS.XMLTYPE");
    stmt.setString(2, userName);
    stmt.execute();
    xmlRes = (XMLType) stmt.getObject(1);
    if (xmlRes != null) {
    String mapString = xmlRes.getStringVal();
    out.println("The map xml for :"+userName+" is "+mapString);
    } catch (SQLException se) {
    out.println(se.getMessage());
    } catch (Exception e) {
    out.println(e.getMessage());
    } finally {
    stmt.close();
    conn.close();
    %>
    Thanks again.

    Given the follow
    SQL> var schemaURL varchar2(256)
    SQL> var schemaPath varchar2(256)
    SQL> --
    SQL> begin
      2    :schemaURL := 'http://localhost:8080/public/mapset.xsd';
      3    :schemaPath := '/public/mapset.xsd';
      4  end;
      5  /
    PL/SQL procedure successfully completed.
    SQL> call dbms_xmlSchema.deleteSchema(:schemaURL,4)
      2  /
    Call completed.
    SQL> declare
      2    res boolean;
      3    xmlSchema xmlType := xmlType(
      4  '<?xml version="1.0" encoding="UTF-8" ?>
      5  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
      6             xmlns:xdb="http://xmlns.oracle.com/xdb"
      7             version="1.0" xdb:storeVarrayAsTable="true">
      8    <!-- definition of simple types -->
      9    <xs:simpleType name="nameType">
    10      <xs:restriction base="xs:string">
    11        <xs:minLength value="1"/>
    12        <xs:maxLength value="50"/>
    13      </xs:restriction>
    14    </xs:simpleType>
    15    <xs:simpleType name="boolType">
    16      <xs:restriction base="xs:unsignedByte">
    17        <xs:minInclusive value="0"/>
    18        <xs:maxInclusive value="1"/>
    19      </xs:restriction>
    20    </xs:simpleType>
    21     <xs:simpleType name="minxType">
    22      <xs:restriction base="xs:string">
    23      </xs:restriction>
    24    </xs:simpleType>
    25     <xs:simpleType name="minyType">
    26      <xs:restriction base="xs:string">
    27      </xs:restriction>
    28    </xs:simpleType>
    29     <xs:simpleType name="maxxType">
    30      <xs:restriction base="xs:string">
    31      </xs:restriction>
    32    </xs:simpleType>
    33     <xs:simpleType name="maxyType">
    34      <xs:restriction base="xs:string">
    35      </xs:restriction>
    36    </xs:simpleType>
    37    <xs:simpleType name="usernameType">
    38      <xs:restriction base="xs:string">
    39        <xs:minLength value="7"/>
    40        <xs:maxLength value="8"/>
    41      </xs:restriction>
    42    </xs:simpleType>
    43    <xs:simpleType name="emailType">
    44      <xs:restriction base="xs:string">
    45        <xs:minLength value="19"/>
    46        <xs:maxLength value="63"/>
    47      </xs:restriction>
    48    </xs:simpleType>
    49     <!-- definition of complex types -->
    50  <xs:complexType name="envType">
    51      <xs:sequence>
    52        <xs:element name="minx"  type="minxType" minOccurs="1" xdb:SQLName="MINX" />
    53        <xs:element name="miny" type="minyType" minOccurs="1" xdb:SQLName="MINY"/>
    54        <xs:element name="maxx"  type="maxxType" minOccurs="1" xdb:SQLName="MAXX" />
    55        <xs:element name="maxy" type="maxyType" minOccurs="1" xdb:SQLName="MAXY"/>
    56      </xs:sequence>
    57    </xs:complexType>
    58   <xs:complexType name="placemarkType">
    59      <xs:sequence>
    60        <xs:element name="placename"  type="nameType" minOccurs="1" xdb:SQLName="PLACENAME"/>
    61        <xs:element name="envelope" type="envType" minOccurs="1" xdb:SQLName="ENVELOPE"/>
    62      </xs:sequence>
    63    </xs:complexType>
    64    <xs:complexType name="layerType">
    65      <xs:sequence>
    66        <xs:element name="layername"  type="nameType" minOccurs="1" xdb:SQLName="LAYERNAME" />
    67        <xs:element name="layerid"  type="nameType" minOccurs="1" xdb:SQLName="LAYERID" />
    68        <xs:element name="service" type="nameType" minOccurs="1" xdb:SQLName="SERVICE"/>
    69        <xs:element name="visible" type="boolType" xdb:SQLName="VISIBLE"/>
    70        <xs:element name="ftype" type="nameType" xdb:SQLName="FTYPE" minOccurs="1" maxOccurs="1"/>
    71      </xs:sequence>
    72    </xs:complexType>
    73     <xs:complexType name="mapType">
    74      <xs:sequence>
    75        <xs:element name="mapname"  type="nameType" minOccurs="1" xdb:SQLName="MAPNAME"/>
    76        <xs:element name="layer"  type="layerType" minOccurs="1" maxOccurs="unbounded" xdb:SQLName="LAYER" />
    77        <xs:element name="placemark" type="placemarkType" minOccurs="1" maxOccurs="unbounded"  xdb:SQLName="PLACEMARK"/>
    78      </xs:sequence>
    79    </xs:complexType>
    80    <xs:complexType name="mapsetType" xdb:SQLType="mapset_t">
    81      <xs:sequence>
    82        <xs:element name="username"  type="usernameType" minOccurs="1" xdb:SQLName="USERNAME" />
    83       <xs:element name="map" type="mapType" minOccurs="1" maxOccurs="unbounded"  xdb:SQLName="MAP" xdb:SQLCollType="MAP_V"/>
    84       <xs:element name="startmap" type="nameType" minOccurs="1" maxOccurs="1" xdb:SQLName="STARTMAP"/>
    85       <xs:element name="startplace" type="nameType" minOccurs="1" maxOccurs="1" xdb:SQLName="STARTPLACE"/>
    86      </xs:sequence>
    87    </xs:complexType>
    88   <!--definition of main element -->
    89    <xs:element name="mapset" type="mapsetType" xdb:defaultTable="MAPSETXML">
    90      <xs:unique name="mapNameKey">
    91         <xs:selector xpath=".//map"/>
    92         <xs:field xpath="mapname"/>
    93      </xs:unique>
    94    </xs:element>
    95    </xs:schema>');
    96  begin
    97    if (dbms_xdb.existsResource(:schemaPath)) then
    98      dbms_xdb.deleteResource(:schemaPath);
    99    end if;
    100    res := dbms_xdb.createResource(:schemaPath,xmlSchema);
    101  end;
    102  /
    PL/SQL procedure successfully completed.
    SQL> begin
      2    dbms_xmlschema.registerSchema
      3    (
      4      :schemaURL,
      5      xdbURIType(:schemaPath).getClob(),
      6      TRUE,TRUE,FALSE,TRUE
      7    );
      8  end;
      9  /
    PL/SQL procedure successfully completed.
    SQL> declare
      2    nested_table_name varchar2(32);
      3  begin
      4    select table_name
      5      into nested_table_name
      6      from user_nested_tables
      7     where table_type_name = 'MAP_V'
      8       and parent_table_name = 'MAPSETXML';
      9
    10     execute immediate 'rename "'|| nested_table_name ||'" to MAP_TABLE';
    11
    12  end;
    13  /
    PL/SQL procedure successfully completed.
    SQL> desc MAPSETXML
    Name                                      Null?    Type
    TABLE of SYS.XMLTYPE(XMLSchema "http://localhost:8080/public/mapset.xsd" Element "mapset") STORAGE Object-relational TYPE "mapset_t"
    SQL> --
    SQL> desc MAP_TABLE
    Name                                      Null?    Type
    SYS_XDBPD$                                         XDB.XDB$RAW_LIST_T
    MAPNAME                                            VARCHAR2(50 CHAR)
    LAYER                                              LAYER7525_COLL
    PLACEMARK                                          PLACEMARK7528_COLL
    SQL> --
    SQL> --
    SQL> create or replace trigger VALIDATE_MAPSET
      2  before insert or update on MAPSETXML
      3  for each row
      4  begin
      5     :new.object_value.schemaValidate();
      6  end;
      7  /
    Trigger created.
    SQL> insert into MAPSETXML values ( xmltype('<mapset>
      2  <username>tester1</username>
      3  <map>
      4  <mapname>Florida</mapname>
      5  <layer>
      6  <layername>Counties</layername>
      7  <layerid>counties</layerid>
      8  <service>base</service>
      9  <visible>1</visible>
    10  <ftype>polygon</ftype>
    11  </layer>
    12  <placemark>
    13  <placename>Florida</placename>
    14  <envelope>
    15  <minx>-186185.234572</minx>
    16  <miny>2709914.999735</miny>
    17  <maxx>596332.812876</maxx>
    18  <maxy>3464678.999670</maxy>
    19  </envelope>
    20  </placemark>
    21  </map>
    22  <startmap>test</startmap>
    23  <startplace>Tallahassee</startplace>
    24  </mapset>
    25  ').createSchemaBasedXML('http://localhost:8080/public/mapset.xsd'))
    26  /
    1 row created.
    SQL> commit
      2  /
    Commit complete.
    SQL> set long 100000
    SQL> --
    SQL> select * from MAPSETXML
      2  /
    SYS_NC_ROWINFO$
    <mapset>
      <username>tester1</username>
      <map>
        <mapname>Florida</mapname>
        <layer>
          <layername>Counties</layername>
          <layerid>counties</layerid>
          <service>base</service>
          <visible>1</visible>
          <ftype>polygon</ftype>
        </layer>
    SYS_NC_ROWINFO$
        <placemark>
          <placename>Florida</placename>
          <envelope>
            <minx>-186185.234572</minx>
            <miny>2709914.999735</miny>
            <maxx>596332.812876</maxx>
            <maxy>3464678.999670</maxy>
          </envelope>
        </placemark>
      </map>
      <startmap>test</startmap>
    SYS_NC_ROWINFO$
      <startplace>Tallahassee</startplace>
    </mapset>
    SQL> CREATE OR REPLACE FUNCTION getMaps(userName varchar2)
      2  RETURN XMLTYPE
      3  AS
      4  xmlDoc XMLTYPE;
      5  BEGIN
      6    SELECT extract(OBJECT_VALUE, '/mapset/map') into xmlDoc
      7    FROM mapsetxml
      8    WHERE existsNode(OBJECT_VALUE,'/mapset['''|| username ||''']')=1;
      9    RETURN xmlDoc;
    10  END;
    11  /
    Function created.
    SQL> select getMaps('Florida') from dual;
    GETMAPS('FLORIDA')
    <map>
      <mapname>Florida</mapname>
      <layer>
        <layername>Counties</layername>
        <layerid>counties</layerid>
        <service>base</service>
        <visible>1</visible>
        <ftype>polygon</ftype>
      </layer>
      <placemark>
        <placename>Florida</placename>
    GETMAPS('FLORIDA')
        <envelope>
          <minx>-186185.234572</minx>
          <miny>2709914.999735</miny>
          <maxx>596332.812876</maxx>
          <maxy>3464678.999670</maxy>
        </envelope>
      </placemark>
    </map>
    SQL>The following Java code
    package com.oracle.st.xmldb.otn;
    import com.oracle.st.xmldb.pm.common.baseApp.BaseApplication;
    import com.oracle.st.xmldb.pm.examples.GetResourceByResourceID;
    import oracle.jdbc.OracleCallableStatement;
    import oracle.jdbc.OracleTypes;
    import oracle.sql.RAW;
    import oracle.xdb.XMLType;
    import oracle.xdb.dom.XDBDocument;
    public class T415572 extends BaseApplication {
        public T415572() {
        public void doSomething(String[] Args) throws Exception
          OracleCallableStatement  statement = null;
          boolean result;
          statement = (OracleCallableStatement) getConnection().prepareCall("{ ? = call getmaps(?)}");
          statement.registerOutParameter(1,OracleTypes.OPAQUE,"SYS.XMLTYPE");
          statement.setString(2,"Florida");
          result = statement.execute();
          XMLType xml = (XMLType) statement.getObject(1);
          statement.close();
          XDBDocument doc = (XDBDocument) xml.getDOM();
          doc.writeToOutputStream(System.out);
          doc.close();
          getConnection().close();
        public static void main (String[] args)
         try
           BaseApplication example = new T415572();
           example.initializeConnection();
           example.doSomething(args);
         catch (Exception e)
           e.printStackTrace();
    }results in
    C:\TEMP>
    C:\Oracle\JDeveloper\jdk\bin\javaw.exe -client -classpath C:\xdb\JDeveloper\Classes;C:\Oracle\product\10.2.0\db_1\jdbc\lib\ojdbc14.jar;C:\Oracle\product\10.2.0\db_1\LIB\xmlparserv2.jar;C:\Oracle\product\10.2.0\db_1\RDBMS\jlib\xdb.jar;C:\xdb\JDeveloper\jakarta-slide-webdavclient-bin-2.1\lib\jakarta-slide-webdavlib-2.1.jar;C:\xdb\JDeveloper\jakarta-slide-webdavclient-bin-2.1\lib\commons-httpclient.jar;C:\xdb\JDeveloper\jakarta-slide-webdavclient-bin-2.1\lib\commons-logging.jar;C:\xdb\JDeveloper\jakarta-slide-webdavclient-bin-2.1\lib\jdom-1.0.jar -Dcom.oracle.st.xmldb.pm.ConnectionParameters=C:\\xdb\\jdeveloper\\SimpleExamples\\LocalConnection.xml -Dhttp.proxyHost=www-proxy.us.oracle.com -Dhttp.proxyPort=80 -Dhttp.nonProxyHosts=192.168.0.77|localhost|192.168.1.1|*.oracle.com|*.us.oracle.com -Dhttps.proxyHost=www-proxy.us.oracle.com -Dhttps.proxyPort=80 -Dhttps.nonProxyHosts=192.168.0.77|localhost|192.168.1.1|*.oracle.com|*.us.oracle.com com.oracle.st.xmldb.otn.T415572 -mx2048M
    ConnectionProvider.establishConnection(): Connecting as SCOTT/TIGER@jdbc:oracle:oci8:@(description=(address=(host=localhost)(protocol=tcp)(port=1521))(connect_data=(service_name=ORA10GR2.xp.mark.drake.oracle.com)(server=DEDICATED)))
    ConnectionProvider.establishConnection(): Database Connection Established
    <map>
      <mapname>Florida</mapname>
      <layer>
        <layername>Counties</layername>
        <layerid>counties</layerid>
        <service>base</service>
        <visible>1</visible>
        <ftype>polygon</ftype>
      </layer>
      <placemark>
        <placename>Florida</placename>
        <envelope>
          <minx>-186185.234572</minx>
          <miny>2709914.999735</miny>
          <maxx>596332.812876</maxx>
          <maxy>3464678.999670</maxy>
        </envelope>
      </placemark>
    </map>
    Process exited with exit code 0.The code also works fine when modified to work with the thin driver...
    Message was edited by:
    mdrake

  • How to return xmlType from Webservice generated with JDev and PL/SQL

    Hi,
    I have generated an PL/SQL package that's returning a value as xmlType.
    With JDeveloper I'm deploying this package as a webservice. When invoking the webservice from a webbrowser the result looks like:
    <?xml version="1.0" encoding="UTF-8" ?>
    <SOAP-ENV:Envelope
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <SOAP-ENV:Body>
    <ns1:testXmltypeResponse
    xmlns:ns1="http://app/webservice.wsdl"
    SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <return xsi:type="xsd:string">
    <ROWSET>
    <ROW>
    <TODAY>12-OCT-07</TODAY>
    </ROW>
    </ROWSET>
    </return>
    </ns1:testXmltypeResponse>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    The problem is that the <return> tag contains 'xsi:type="xsd:string"'. And now the webservice response is not valid XML because the return value contains XML and not a string.
    The solution would be, when invoking the webservice if the xsi:type would be missing from the result tag or would contains xsd:any. I tried editing the WSDL in JDeveloper and changing the type to xsd:any. After deploying and calling the WSDL from the webbrowser it contains this type. But when invoking the method from the webbrowser it still returns xsd:string as type.
    How can I get rid of this type in the <return> or change it.
    My JDeveloper version is 10.1.3.3.0 The Oracle database and 9iAS are 10.2.
    Thanks in advance,
    Thijs

    What version are you on?
    Works fine for me on my 11g:
    SQL> create or replace procedure testxml (clob_out out clob)
      2  is
      3     l_clob   clob;
      4     l_ctx    dbms_xmlquery.ctxhandle;
      5  begin
      6     l_ctx := dbms_xmlquery.newcontext ('select * from dual');
      7     l_clob := dbms_xmlquery.getxml (l_ctx);
      8     clob_out := l_clob;
      9     dbms_xmlquery.closecontext (l_ctx);
    10  end testxml;
    11  /
    Procedure created.
    SQL>
    SQL> variable vout clob;
    SQL>
    SQL> exec testxml (:vout)
    PL/SQL procedure successfully completed.
    SQL>
    SQL> print vout
    VOUT
    <?xml version = '1.0'?>
    <ROWSET>
       <ROW num="1">
          <DUMMY>X</DUMMY>
       </ROW>
    </ROWSET>But definitely you can optimize your proc a bit: Try
    create or replace procedure testxml (clob_out in out nocopy clob)
    is
       l_ctx    dbms_xmlquery.ctxhandle;
    begin
       l_ctx := dbms_xmlquery.newcontext ('select * from dual');
       clob_out := dbms_xmlquery.getxml (l_ctx);
       dbms_xmlquery.closecontext (l_ctx);
    end testxml;
    /

  • EBS ISG using custom PL/SQL functions that return XMLType

    Hi,
    We have a custom PL/SQL package that we use for interfacing systems and some of the functions in this package ruturn an XMLType. We want to deploy the package functions as web services through the ISG, but it is not working as expected. When deployed through the ISG, the functions with XMLType return type produce a null response from the ISG (they work fine when called in SQL or PL/SQL; functions with non-XMLTypes work fine).
    If we change the return type to CLOB (and use getClobVal() on the XMLType) then we get a response from the ISG, but it changes all the angle-brackets in the CLOB (which is still arbitrary XML text) to &lt; &gt; ...
    What is the proper way to get the complex XMLType output through the ISG? Anyone have any more experience?
    Thanks,
    --Walt                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Alex,
    For the predicate groups that are indexed/stored, the exact operator types (as in equality, inequality, like etc) that are indexed are specified while assigning the default index parameters. In the following example, exf$indexoper is used to specify the list of indexed operators.
    BEGIN
      DBMS_EXPFIL.DEFAULT_INDEX_PARAMETERS('Car4Sale',
        exf$attribute_list (
           exf$attribute (attr_name => 'HorsePower(Model, Year)',
                          attr_oper => exf$indexoper('=','<','>','>=','<='),
                          attr_indexed => 'FALSE')    --- stored predicate group
    END;
    /You can find more information about exf$indexoper at
    http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28419/t_expfilobj.htm#ARPLS153
    Could you confirm that you chose to index 'is null' and 'is not null' while assigning the default index parameters ? This information is available in OPERATOR_LIST column of the USER_EXPFIL_DEF_INDEX_PARAMS view.
    Hope this helps,
    -Aravind.

  • 10g XMLTABLE - can I return XMLTYPE col as well as extract specific columns

    Hi,
    (This is for version 10.2.0.4)
    Currently, we have a giant XML column which contains many parts to it. We split those into individual parts via XMLSEQUENCE and then loop through to extract information from two other XMLTYLE columns. I'd like to be able to use XMLTABLE to join the XMLTYPE columns to each other in one SQL statement, as I think it should be more efficient. (We're having issues when the big XML column has 400 or more parts in it - looping and doing extract values on two xmltype columns 400+ times is proving slow going!)
    Anyway, what I'd like to do is use XMLTABLE to produce a table-like structure for each column, then join them so that 1st part in col1 = 1st part in col2 = 1st part in col3.
    I've looked around at the documentation and google, but I'm getting stuck at one particular point - I would like to return both the XMLTYPE and specific extracted values from that XMLTYPE as part of the XMLTABLE on each column. I just can't seem to find a way to do it.
    Here's an example (that I've nabbed from http://thinktibits.blogspot.com/2011/03/oracle-xmltable-example-part-1.html ) that will hopefully explain more clearly what I'd like to do, taking just one column to start with:
    CREATE TABLE xml_test
    (NOTEBOOK XMLTYPE);
    insert into xml_test values ('<?xml version="1.0" encoding="UTF-8"?><Product Type=''Laptop''><Notebook Brand="HP" Model="Pavilion dv6-3132TX Notebook"><Harddisk>640 GB</Harddisk><Processor>Intel Core i7</Processor><RAM>4 GB</RAM></Notebook><Notebook Brand="HP" Model="HP Pavilion dv6-3032TX Notebook"><Harddisk>640 GB</Harddisk><Processor>Intel Core i7</Processor><RAM>6 GB</RAM></Notebook><Notebook Brand="Toshiba" Model="Satellite A660/07R 3D Notebook"><Harddisk>640 GB</Harddisk><Processor>Intel Core i7</Processor><RAM>4 GB</RAM></Notebook><Notebook Brand="Toshiba" Model="Satellite A660/15J Notebook"><Harddisk>640 GB</Harddisk><Processor>Intel Core i5</Processor><RAM>6 GB</RAM></Notebook></Product>');
    commit;
    SELECT NOTEBOOKS1.*
      FROM xml_test PO,
           XMLTable('//Notebook' PASSING PO.NOTEBOOK) notebooks1;
    COLUMN_VALUE                                                                                                                                          
    <Notebook Brand="HP" Model="Pavilion dv6-3132TX Notebook"><Harddisk>640 GB</Harddisk><Processor>Intel Core i7</Processor><RAM>4 GB</RAM></Notebook>
    <Notebook Brand="HP" Model="HP Pavilion dv6-3032TX Notebook"><Harddisk>640 GB</Harddisk><Processor>Intel Core i7</Processor><RAM>6 GB</RAM></Notebook>
    <Notebook Brand="Toshiba" Model="Satellite A660/07R 3D Notebook"><Harddisk>640 GB</Harddisk><Processor>Intel Core i7</Processor><RAM>4 GB</RAM></Notebook>
    <Notebook Brand="Toshiba" Model="Satellite A660/15J Notebook"><Harddisk>640 GB</Harddisk><Processor>Intel Core i5</Processor><RAM>6 GB</RAM></Notebook>
    4 rows selected.
    SELECT NOTEBOOKS2.*
      FROM xml_test PO,
           XMLTable('//Notebook' PASSING PO.NOTEBOOK
           COLUMNS  row_num for ordinality,
                    "BrandType"    CHAR(10) PATH '@Brand',
                    "ProductModel" CHAR(50) PATH '@Model',
                    "Harddisk" CHAR(10) PATH 'Harddisk',
                    "Processor" CHAR(20) PATH 'Processor',
                    "RAM" CHAR(10) PATH 'RAM') AS NOTEBOOKS2;
       ROW_NUM BrandType  ProductModel                                       Harddisk   Processor            RAM      
             1 HP         Pavilion dv6-3132TX Notebook                       640 GB     Intel Core i7        4 GB     
             2 HP         HP Pavilion dv6-3032TX Notebook                    640 GB     Intel Core i7        6 GB     
             3 Toshiba    Satellite A660/07R 3D Notebook                     640 GB     Intel Core i7        4 GB     
             4 Toshiba    Satellite A660/15J Notebook                        640 GB     Intel Core i5        6 GB     
    4 rows selected.What I'd like is to have the COLUMN_VALUE contents from the first select to appear as a column in the second select - is it possible?
    At worst case, I could do a join, only that produces a cartesian product because I don't know how to label the rows from within the first query's XMLTABLE (if I used rownum in the query itself, does that guarentee to come out in the same order as the XMLTABLE results? Would part 1 always be labeled row 1, part 2 row2, etc?).
    I hope that makes some sort of sense - I'm not up on XML terms, sadly.
    ETA: If there's no way of doing this via XMLTABLE, is there any other way of achieving it?
    Edited by: Boneist on 02-Dec-2011 17:14

    Hi,
    Define an additional XMLType projection in the COLUMNS clause with PATH = '.' (the context item) :
    SQL> set long 500
    SQL>
    SQL> SELECT x1.*
      2  FROM xml_test t
      3     , XMLTable('/Product/Notebook' PASSING t.notebook
      4         COLUMNS rn FOR ORDINALITY
      5               , BrandType      VARCHAR2(10) PATH '@Brand'
      6               , ProductModel   VARCHAR2(50) PATH '@Model'
      7               , Harddisk       VARCHAR2(10) PATH 'Harddisk'
      8               , Processor      VARCHAR2(20) PATH 'Processor'
      9               , RAM            VARCHAR2(10) PATH 'RAM'
    10               , NoteBook_node  XMLType      PATH '.'
    11       ) x1
    12  ;
            RN BRANDTYPE  PRODUCTMODEL                                       HARDDISK   PROCESSOR            RAM        NOTEBOOK_NODE
             1 HP         Pavilion dv6-3132TX Notebook                       640 GB     Intel Core i7        4 GB       <Notebook Brand="HP" Model="Pavilion dv6-3132TX Notebook">
                                                                                                                          <Harddisk>640 GB</Harddisk>
                                                                                                                          <Processor>Intel Core i7</Processor>
                                                                                                                          <RAM>4 GB</RAM>
                                                                                                                        </Notebook>
             2 HP         HP Pavilion dv6-3032TX Notebook                    640 GB     Intel Core i7        6 GB       <Notebook Brand="HP" Model="HP Pavilion dv6-3032TX Notebook">
                                                                                                                          <Harddisk>640 GB</Harddisk>
                                                                                                                          <Processor>Intel Core i7</Processor>
                                                                                                                          <RAM>6 GB</RAM>
                                                                                                                        </Notebook>
             3 Toshiba    Satellite A660/07R 3D Notebook                     640 GB     Intel Core i7        4 GB       <Notebook Brand="Toshiba" Model="Satellite A660/07R 3D Notebook">
                                                                                                                          <Harddisk>640 GB</Harddisk>
                                                                                                                          <Processor>Intel Core i7</Processor>
                                                                                                                          <RAM>4 GB</RAM>
                                                                                                                        </Notebook>
             4 Toshiba    Satellite A660/15J Notebook                        640 GB     Intel Core i5        6 GB       <Notebook Brand="Toshiba" Model="Satellite A660/15J Notebook">
                                                                                                                          <Harddisk>640 GB</Harddisk>
                                                                                                                          <Processor>Intel Core i5</Processor>
                                                                                                                          <RAM>6 GB</RAM>
                                                                                                                        </Notebook>
    I'm not sure I understand the rest of your requirement.
    Do you want to further break the generated XMLType into a set of relational rows, or repeat the operation on different columns from the same base table?

  • Help Query returns XMLType

    I'm unable get XML output from the most basic of queries. I'm currently working through the Sql In Xml out document. Everytime i try to output xml i get a list (without errors) of
    EMPLOYEE
    <Xmltype>
    <Xmltype>
    <Xmltype>
    <Xmltype>
    <Xmltype>
    for each record. Can anyone help.
    Im running 10g release 2.

    A couple more questions
    First, is the XML stored in the table as XMLType column with a schema?
    Second, in sqplus, on 10R2, I just ran the following query, try it and see if what you get.
    select xmlforest(object_name as "name") from user_objects where object_type = 'TABLE' and rownum < 5;
    XMLFOREST(OBJECT_NAMEAS"NAME")
    <name>BIN$+1aDxmVbQIau51oiplxCAw==$0</name>
    <name>BIN$+3Y2EpX4TvGY4j1SIGBAMQ==$0</name>
    <name>BIN$+AugUYpGSS29uaP5DnYsZQ==$0</name>
    <name>BIN$+ptFT7gqTX2GgNrndS5azw==$0</name>
    Elapsed: 00:00:00.02
    of course your names will vary.
    Scott

  • Help using Java to retrieve XMLType returned from PL/SQL stored object

    Hi,
    Please bear with me if this is a trivial question. I'm brand new to Java, JDBC, and XML DB. I've been spinning my wheels on this for a few hours now.
    I have a table:
    XMLDB_USER@xmldb64> desc my_test_table
    Name                                      Null?    Type
    ID                                                 NUMBER(9)
    DOC                                                SYS.XMLTYPE(XMLSchema "http:
                                                        //www.myproquest.com/Global_
                                                        Schema_v3.0.xsd" Element "RE
                                                        CORD") STORAGE BINARYI've written a trivially simple PL/SQL function to retrieve the DOC column, based on the ID passed to it.
    create or replace function get_doc(goid in number) return xmltype is
      doc_content xmltype;
    begin
      select doc into doc_content from my_test_table where id = goid;
      return doc_content;
    end;
    /Up to here, everything works fine. I wrote a small anonymous PL/SQL block, and proved that I can call the PL/SQL function successfully.
    Now, I want to implement in Java. This is where I get confused.
    Currently my code looks like this:
    import java.sql.*;
    import oracle.jdbc.*;
    import oracle.jdbc.OracleTypes;
    import oracle.jdbc.pool.OracleDataSource;
    import oracle.xdb.*;
    import java.io.*;
    import java.lang.StringBuilder;
    import java.sql.Clob;
    class MyJava
      public static void main(String args[]) throws SQLException, IOException
        Clob xml = null;
        System.out.print("Connecting to the database...");
        System.out.flush();
        OracleDataSource ods = new OracleDataSource();
        String URL = "jdbc:oracle:thin:@//pqhdb201.aa1.pqe:1522/xmldb64";
        ods.setURL(URL);
        ods.setUser("xmldb_user");
        ods.setPassword("xmldb_user");
        Connection conn = ods.getConnection();
        System.out.println("connected.");
        System.out.println("GOID to be retrieved is " + args[0]);
        CallableStatement cs1 = null;
    try {
        cs1 = conn.prepareCall( "{? = call get_doc (?)}" );
        cs1.registerOutParameter(1,OracleTypes.OPAQUE,"XMLType");
        cs1.setString(2,args[0]);
        cs1.execute();
    //    xml = XMLType.createXML(cs1.getOPAQUE(1));
        xml = (Clob) cs1.getObject(1);
    //    System.out.println(((XMLType)xml).getStringVal());
    //    System.out.println(xml.getClobVal());
        System.out.println(xml.getCharacterStream());
      finally {
         if(cs1!=null) cs1.close();
         if(conn!=null) conn.close();
    }This compiles, but when I run, I get:
    pqhdb201:[xmldb64]:(/home/oracle/xmldb_scripts):$java MyJava 91455713
    Connecting to the database...connected.
    GOID to be retrieved is 91455713
    Exception in thread "main" java.sql.SQLException: invalid name pattern: XMLDB_USER.XMLType
            at oracle.jdbc.oracore.OracleTypeADT.initMetadata(OracleTypeADT.java:553)
            at oracle.jdbc.oracore.OracleTypeADT.init(OracleTypeADT.java:469)
            at oracle.sql.OpaqueDescriptor.initPickler(OpaqueDescriptor.java:237)
            at oracle.sql.OpaqueDescriptor.<init>(OpaqueDescriptor.java:104)
            at oracle.sql.OpaqueDescriptor.createDescriptor(OpaqueDescriptor.java:220)
            at oracle.sql.OpaqueDescriptor.createDescriptor(OpaqueDescriptor.java:181)
            at oracle.jdbc.driver.NamedTypeAccessor.otypeFromName(NamedTypeAccessor.java:83)
            at oracle.jdbc.driver.TypeAccessor.initMetadata(TypeAccessor.java:89)
            at oracle.jdbc.driver.T4CCallableStatement.allocateAccessor(T4CCallableStatement.java:689)
            at oracle.jdbc.driver.OracleCallableStatement.registerOutParameterInternal(OracleCallableStatement.java:157)
            at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:202)
            at oracle.jdbc.driver.OracleCallableStatementWrapper.registerOutParameter(OracleCallableStatementWrapper.java:1356)
            at MyJava.main(MyJava.java:29)As you can see from the commented lines, I've tried several different approaches, based on various examples from Oracle documentation and various samples found on the net. My problem, I think, is that I have a fundamental disconnect somewhere. Objects? Types? Different methods? getClobVal? getStringVal? getCharacterStream? I'm still trying to get up to speed on all the lingo and terminology, and, as a result, I suspect I'm asking the wrong questions, and getting wrong results.
    Based on the simple example above, my table and PL/SQL function definitions, can someone help me fill in the gaps of what I'm missing in terms of the Java code?
    Thanks!
    -Mark

    Hi, I´ve been working on an application that return an XMLTYPE from an schema package, the XML is generated in a query, not read it in a table, and use that variable in a JSP.
    The DDL of the package function is this:
    CREATE OR REPLACE
    PACKAGE BODY pkg_modulos
    IS
        FUNCTION obtenerModulos (pAnio IN NUMBER DEFAULT 2011)
            RETURN XMLTYPE
        IS
            x    XMLTYPE;
        BEGIN
            SELECT  XMLELEMENT ("tree", XMLAttributes (0 AS "id"),
                        (SELECT  DBMS_XMLGEN.getxmltype(DBMS_XMLGEN.newcontextfromhierarchy('SELECT level,
                                              XMLElement("item",
                                                                          XMLAttributes(
                                                                    m.idmodulo as "id",
                                                                    m.nombre AS "text"))
                                FROM            modulos m
                 WHERE m.anio = 2011
    CONNECT BY   PRIOR m.idmodulo = m.padre
    START WITH   m.padre IS NULL'))
                            FROM     DUAL))
                            arbolXML
              INTO  x
              FROM  DUAL;
            RETURN x;
        END;                                                                         
    END;   as far as I see there shouldn´t be any problems with this code
    The problem is on the JSP code
    this is my code:
    <?xml version="1.0" encoding="UTF-8"?>
    <%@ page contentType="text/xml; charset=UTF-8" import="java.io.*,java.lang.*,java.sql.*,java.util.*,oracle.jdbc.*,oracle.xdb.*, oracle.jdbc.OracleTypes,oracle.jdbc.pool.OracleDataSource"%>
    <%
      Connection dbconn;
      OracleDataSource ods = new OracleDataSource();
      OracleCallableStatement stmt;
        try
             String hostname="localhost";
             String dbname="xe";
             String usr="seguridad";
             String pass="seguridad";
             String URL = "jdbc:oracle:thin:@"+hostname+":1521:"+dbname;
             ods.setURL(URL);
            ods.setUser(usr);
            ods.setPassword(pass);
             dbconn = ods.getConnection();
              String st=request.getParameter("st").toString();
              int np=Integer.parseInt(request.getParameter("np").toString());     
              stmt = (OracleCallableStatement)dbconn.prepareCall( "begin ? := "+st+"; end;" );
              stmt.registerOutParameter(1,OracleTypes.OPAQUE,"SYS.XMLTYPE");          
              stmt.execute();
              XMLType xml = null;
              xml = (XMLType) stmt.getObject(1);
              System.out.println(xml.getStringVal());
              stmt.close();
              dbconn.close();
        catch (SQLException s)
          out.println("SQL Error: " + s.toString());
           System.out.println("SQL Error: " + s.toString());
    %>I´m getting te error:
    SQL Error: java.sql.SQLException: inconsistent java and sql object types: SYS.XMLTYPE
    Making a debbuging I identified that the exception is been raised in this line:
    xml = (XMLType) stmt.getObject(1);I´ve been checking a lot of online documentation but I´ve not been able to make it work
    If anyone could help me please, I don´t know what else to do
    Thanks... sorry for the english

  • How do i add a root node to a XMLType

    Hi all
    I have a problem inserting a root node in a xml document generated by DBMS_XMLGEN.newcontextfromhierarchy. The function get_site_map_nodes generates a document like this:
    <?xml version="1.0"?>
    <siteMapNode f_page_id="1" title="rot" PATH="1">
    <siteMapNode f_page_id="2" title="1.1" PATH="1.1">
    <siteMapNode f_page_id="4" title="1.1.1" PATH="1.1.1"/>
    </siteMapNode>
    <siteMapNode f_page_id="3" title="1.2" PATH="1.2"/>
    <siteMap/>
    </siteMapNode>
    This is correct but i want to add a root node so the result shows as below:
    <?xml version="1.0"?>
    <siteMap>
    <siteMapNode f_page_id="1" title="rot" PATH="1">
    <siteMapNode f_page_id="2" title="1.1" PATH="1.1">
    <siteMapNode f_page_id="4" title="1.1.1" PATH="1.1.1"/>
    </siteMapNode>
    <siteMapNode f_page_id="3" title="1.2" PATH="1.2"/>
    <siteMap/>
    </siteMapNode>
    </siteMap>
    The problem is that i have no clue how to accomplish this.
    Best regards
    Daniel Carlsson
    PACKAGE BODY PKG_PAGE_STRUCTURE
    IS
    FUNCTION get_level_path (in_page_id IN page_structure.f_page_id%TYPE)
    RETURN VARCHAR2
    IS
    l_path VARCHAR2 (4000) := '';
    BEGIN
    SELECT MAX (SYS_CONNECT_BY_PATH (f_show_order, '.'))
    INTO l_path
    FROM page_structure
    START WITH f_page_id = in_page_id
    CONNECT BY PRIOR f_parent_page = f_page_id;
    l_path := RTRIM (l_path, '.');
    RETURN l_path;
    END get_level_path;
    FUNCTION get_site_map_nodes (in_page_id IN page_structure.f_page_id%TYPE)
    RETURN XMLTYPE
    IS
    qryctx DBMS_XMLGEN.ctxhandle;
    l_xml XMLTYPE;
    BEGIN
    qryctx :=
    DBMS_XMLGEN.newcontextfromhierarchy
    ('select level, xmlelement("siteMapNode", XMLAttributes(f_page_id as "f_page_id",
    f_title_phrase as "title", pkg_page_structure.get_level_path(f_page_id) as path))
    FROM PAGE_STRUCTURE
    START WITH f_page_id = :in_page_id
    connect by f_parent_page = prior f_page_id
    ORDER siblings BY f_show_order'
    DBMS_XMLGEN.setbindvalue (qryctx, 'in_page_id', TO_CHAR (in_page_id));
    l_xml := DBMS_XMLGEN.getxmltype (qryctx);
    DBMS_XMLGEN.closecontext (qryctx);
    RETURN l_xml;
    END get_site_map_nodes;
    END PKG_PAGE_STRUCTURE;
    CREATE TABLE page_structure
    (f_page_id NUMBER(10,0) NOT NULL,
    f_parent_page NUMBER(10,0),
    f_show_order NUMBER(10,0),
    f_title_phrase VARCHAR2(20),
    f_created_by NUMBER(10,0),
    f_created_date DATE,
    f_updated_by NUMBER(10,0),
    f_updated_date DATE)
    INSERT INTO page_structure
    (F_PAGE_ID,F_PARENT_PAGE,F_SHOW_ORDER,F_TITLE_PHRASE,F_CREATED_BY,F_CREATED_DATE,F_UPDATED_BY,F_UPDATED_DATE)
    VALUES
    (1,NULL,1,'rot',1,'30-MAR-2006',NULL,NULL)
    INSERT INTO page_structure
    (F_PAGE_ID,F_PARENT_PAGE,F_SHOW_ORDER,F_TITLE_PHRASE,F_CREATED_BY,F_CREATED_DATE,F_UPDATED_BY,F_UPDATED_DATE)
    VALUES
    (2,1,1,'1.1',1,'30-MAR-2006',NULL,NULL)
    INSERT INTO page_structure
    (F_PAGE_ID,F_PARENT_PAGE,F_SHOW_ORDER,F_TITLE_PHRASE,F_CREATED_BY,F_CREATED_DATE,F_UPDATED_BY,F_UPDATED_DATE)
    VALUES
    (3,1,2,'1.2',1,'30-MAR-2006',NULL,NULL)
    INSERT INTO page_structure
    (F_PAGE_ID,F_PARENT_PAGE,F_SHOW_ORDER,F_TITLE_PHRASE,F_CREATED_BY,F_CREATED_DATE,F_UPDATED_BY,F_UPDATED_DATE)
    VALUES
    (4,2,1,'1.1.1',1,'30-MAR-2006',NULL,NULL)
    /

    Please try below steps.
    1. Complete Prerequisite for adding cluster node
    2. Verify the node is accessible to all other nodes in the cluster. Run the following command from the existing node in the cluster.
    cluvfy stage -pre crsinst -n newNode
    3. Run cluvfy from any existing node
    cluvfy stage -pre nodeadd -n <New Node>
    Note : If cluvfy in above step shows any errors fix those and then proceed with this step
    4. Change Directory to Clusterware Home and execute addNode scripts from any existing node.
    cd $CRS_HOME/oui/bin
    ./addNode.sh -silent "CLUSTER_NEW_NODES={ <NewNode > } CLUSTER_NEW_PRIVATE_NODE_NAMES={ <Interconnect >} CLUSTER_NEW_VIRTUAL_HOSTNAMES={ < Virtual Host Name >}"
    At the end of addNode, script will prompt to run for root.sh on newly added node.
    5. Verify Node is successfully added
    cluvfy stage -post nodeadd -n <NewNode >
    6. Verify CRS Stack is running on the new Node.
    $CRS_HOME/bin/crs_stat -t
    7. To extend the Oracle RAC Installation to include the new Node, run addNode from $ORACLE_HOME/oui/bin from existing node in the cluster
    cd $CRS_HOME/oui/bin
    ./addNode.sh
    When OUI displays the Specify Cluster Nodes to Add to Installation window, select the node to be added, then click Next .
    Verify the summary and run root.sh on new node when it prompts.
    8. Adding New Instance on the New Node
    $CRS_HOME/bin/lsnrctl status
    9.Run $ORACLE_HOME/bin/dbca from any of the existing RAC Instances Oracle Home.
    Select Oracle Real Application Clusters database , and then click Next .
    Select Instance Management , and then click Next .
    Select Add an Instance , then click Next .
    Click Next to accept default instance name or it can be changed.
    Check the summary window.
    Note: Please check these steps in test environment first.
    HTH

  • Size limit on xmlType CLOB?

    I seem to be running into a limit on the size of the CLOB returned from a select into an XMLType. When it gets around 275K it doesn't return a value anymore - it does not return an error, just the .getclobval is empty. I am using the Select XMLAgg(XMLElement) Into XMLType method. Using 9.2 ORA DB running on UNIX. If anybody knows if there is actually a limit, it would be greatly appreciated. I know I can use the dbms_xmlgen method but I want to avoid that if possible.
    The full stored proc text:
    PROCEDURE GetISRNumber ( RetXML OUT CLOB ) IS
    xmlTypeRet xmlType;
    begin
    SELECT xmlagg(XMLELEMENT("Record", XMLELEMENT("JobNumber", ISR.ISR_NO)
    , XMLELEMENT( "address", isr.COMPL_ADDRESS)
    , XMLElement( "Street", isr.Street_Name1)
    , XMLElement( "CivicExtensionDFJOIK", isr.ALPHA_CIVIC)
    , XMLElement( "Created_Date", isr.created_date)
    )) AS "XMLReturned"
    INTO xmlTypeRet
    (Select ISR_NO, COMPL_ADDRESS, Street_Name1, ALPHA_CIVIC, Created_Date FROM ISR)
    RetXML := xmltyperet.getclobval();
    RetXML := '<Job>' || RetXML || '</Job>';
    EXCEPTION
    WHEN OTHERS THEN
    Case SQLCODE
    When -30625 Then
    RetXML := '<Job>No Records Found</Job>';
    Else
    Raise;
    END CASE;
    end GetISRNumber;

    This link will be usefull
    for this problem
    http://www.oracle.com/technology/sample_code/tech/java/codesnippet/xmldb/HowToLoadLargeXML.html

  • 275K Limit on xmlType CLOB?

    I seem to be running into a limit on the size of the CLOB returned from a select into an XMLType. When it gets around 275K it doesn't return a value anymore - it does not return an error, just the .getclobval is empty. I am using the Select XMLAgg(XMLElement) Into XMLType method. Using 9.2 ORA DB running on UNIX. If anybody knows if there is actually a limit, it would be greatly appreciated. I know I can use the dbms_xmlgen method but I want to avoid that if possible.
    The full stored proc text:
    PROCEDURE GetISRNumber ( RetXML OUT CLOB ) IS
    xmlTypeRet xmlType;
    begin
    SELECT xmlagg(XMLELEMENT("Record", XMLELEMENT("JobNumber", ISR.ISR_NO)
    , XMLELEMENT( "address", isr.COMPL_ADDRESS)
    , XMLElement( "Street", isr.Street_Name1)
    , XMLElement( "CivicExtensionDFJOIK", isr.ALPHA_CIVIC)
    , XMLElement( "Created_Date", isr.created_date)
    )) AS "XMLReturned"
    INTO xmlTypeRet
    FROM isr ISR ;
    RetXML := xmltyperet.getclobval();
    RetXML := '<Job>' || RetXML || '</Job>';
    EXCEPTION
    WHEN OTHERS THEN
    Case SQLCODE
    When -30625 Then
    RetXML := '<Job>No Records Found</Job>';
    Else
    Raise;
    END CASE;
    end GetISRNumber;

    Please post the question at
    PL/SQL XML Programming
    for quick response.

  • 4.0 EA1 - Cannot select from table with xmltype

    Hi,
    I have the following table. When doing a select * from horus_owner.horus_objects nothing is shown. This could be reproduced with both 10g and 11g on the database-side.
    Regards,
    Johannes
    -- Wiedergabe von TABLE DDL für Objekt HORUS_OWNER.HORUS_OBJECTS nicht möglich, da DBMS_METADATA internen Generator versucht.
    CREATE TABLE HORUS_OWNER.HORUS_OBJECTS
      ID NUMBER(32, 0) NOT NULL
    , TRE_ID NUMBER(32, 0) NOT NULL
    , WRK_ID NUMBER(32, 0) NOT NULL
    , NAME VARCHAR2(200 BYTE) NOT NULL
    , MOD_TYPE VARCHAR2(10 BYTE) NOT NULL
    , LOCKED_BY VARCHAR2(30 BYTE)
    , PETRI_XML SYS.XMLTYPE
    , AOM_XML SYS.XMLTYPE
    , SHM_XML SYS.XMLTYPE
    , ORG_XML SYS.XMLTYPE
    , ROLE_XML SYS.XMLTYPE
    , MIT_XML SYS.XMLTYPE
    , RUL_XML SYS.XMLTYPE
    , TXT_DATA CLOB
    , CREATED DATE NOT NULL
    , CREATED_BY VARCHAR2(30 BYTE) NOT NULL
    , UPDATED_BY VARCHAR2(30 BYTE)
    , UPDATED DATE
    , SIM_XML SYS.XMLTYPE
    , GLOSSARY_XML SYS.XMLTYPE
    , CONSTRAINT OBJ_PK PRIMARY KEY
        ID
      ENABLE
    LOGGING
    TABLESPACE HORUS_OWNER_DATA
    PCTFREE 10
    INITRANS 1
    STORAGE
      INITIAL 65536
      NEXT 1048576
      MINEXTENTS 1
      MAXEXTENTS UNLIMITED
      BUFFER_POOL DEFAULT
    ) NOCOMPRESS
    XMLTYPE PETRI_XML STORE AS CLOB
    XMLTYPE AOM_XML STORE AS CLOB
    XMLTYPE SHM_XML STORE AS CLOB
    XMLTYPE ORG_XML STORE AS CLOB
    XMLTYPE ROLE_XML STORE AS CLOB
    XMLTYPE MIT_XML STORE AS CLOB
    XMLTYPE RUL_XML STORE AS CLOB
    LOB (TXT_DATA) STORE AS SYS_LOB0000024538C00021$$
      ENABLE STORAGE IN ROW
      CHUNK 8192
      RETENTION
      NOCACHE
      LOGGING 
    XMLTYPE SIM_XML STORE AS CLOB
    XMLTYPE GLOSSARY_XML STORE AS CLOBALTER TABLE HORUS_OWNER.HORUS_OBJECTS
    ADD CONSTRAINT OBJ_UK UNIQUE
      WRK_ID
    , NAME
    , TRE_ID
    ENABLEALTER TABLE HORUS_OWNER.HORUS_OBJECTS
    ADD CONSTRAINT OBJ_TRE_FK FOREIGN KEY
      TRE_ID
    REFERENCES HORUS_OWNER.HORUS_TREE_NODES
      ID
    ENABLEALTER TABLE HORUS_OWNER.HORUS_OBJECTS
    ADD CONSTRAINT AVCON_1243352806_MOD_T_000 CHECK
    (MOD_TYPE
    IN ('EMP', 'ROL', 'ENT', 'OCH', 'XML', 'SHM', 'OSM', 'BUM', 'BOM',
    'BEH', 'KPI', 'RIS', 'SER', 'STR', 'SWO', 'AOM', 'CON', 'GOA', 'BUR'
    , 'BPA', 'RES', 'SIM', 'GLO','TEM', 'SAR'))
    ENABLECREATE UNIQUE INDEX HORUS_OWNER.OBJ_PK ON HORUS_OWNER.HORUS_OBJECTS (ID ASC)
    LOGGING
    TABLESPACE HORUS_OWNER_IDX
    PCTFREE 10
    INITRANS 2
    STORAGE
      INITIAL 65536
      NEXT 1048576
      MINEXTENTS 1
      MAXEXTENTS UNLIMITED
      BUFFER_POOL DEFAULT
    NOPARALLEL
    CREATE INDEX HORUS_OWNER.OBJ_TRE_FK_I ON HORUS_OWNER.HORUS_OBJECTS (TRE_ID ASC)
    LOGGING
    TABLESPACE HORUS_OWNER_IDX
    PCTFREE 10
    INITRANS 2
    STORAGE
      INITIAL 65536
      NEXT 1048576
      MINEXTENTS 1
      MAXEXTENTS UNLIMITED
      BUFFER_POOL DEFAULT
    NOPARALLEL
    CREATE UNIQUE INDEX HORUS_OWNER.OBJ_UK ON HORUS_OWNER.HORUS_OBJECTS (WRK_ID ASC, NAME ASC, TRE_ID ASC)
    LOGGING
    TABLESPACE HORUS_OWNER_IDX
    PCTFREE 10
    INITRANS 2
    STORAGE
      INITIAL 65536
      NEXT 1048576
      MINEXTENTS 1
      MAXEXTENTS UNLIMITED
      BUFFER_POOL DEFAULT
    NOPARALLEL
    CREATE INDEX HORUS_OWNER.OBJ_WRK_FK_I ON HORUS_OWNER.HORUS_OBJECTS (WRK_ID ASC)
    LOGGING
    TABLESPACE HORUS_OWNER_IDX
    PCTFREE 10
    INITRANS 2
    STORAGE
      INITIAL 65536
      NEXT 1048576
      MINEXTENTS 1
      MAXEXTENTS UNLIMITED
      BUFFER_POOL DEFAULT
    NOPARALLEL

    Not sure if this helps, but I was trying to come up with some test cases myself and I noticed some strange behavior.  4 simple test cases:
    SELECT XMLTYPE('<OUTER><INNER>TEST</INNER></OUTER>') FROM DUAL;
    SELECT XMLELEMENT("OUTER", XMLELEMENT("INNER", 'TEST')) FROM DUAL;
    SELECT XMLELEMENT("OUTER", XMLAGG(XMLFOREST('TEST' "INNER"))) FROM DUAL;
    SELECT XMLQUERY('/OUTER' PASSING XMLTYPE('<OUTER><INNER>TEST</INNER></OUTER>') RETURNING CONTENT) FROM DUAL;
    1 and 2 return the xml string in the result grid column.  3 and 4 return (XMLTYPE) with no data in the pop-up editor when double clicking the result.  I changed #3 to:
    SELECT XMLELEMENT("OUTER", XMLFOREST('TEST' "INNER")) FROM DUAL;
    and it returns the XML string.
    I used undo to revert back to my original #3 and it started showing the XML string instead of (XMLTYPE) previously observed.
    I changed my connection to another schema, ran #3 again, and it went back to (XMLTYPE).  I tried to recreate the same behavior using the 2nd schema, but I was unable to get to show the XML string. 
    In any test case where I was getting the (XMLTYPE), I was not able to see data in the pop-up editor.
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production    
    PL/SQL Release 11.2.0.3.0 - Production                                          
    CORE 11.2.0.3.0 Production                                                        
    TNS for HPUX: Version 11.2.0.3.0 - Production                                   
    NLSRTL Version 11.2.0.3.0 - Production 

  • Error using XMLTYPE & Cursor

    Please help me on rectifying my query. this query returns
    ORA-06502: PL/SQL: numeric or value error
    ORA-06512: at "SYS.XMLTYPE", line 343
    ORA-06512: at line 1
                   SELECT          xmlelement("worflowAGMT",
                   XMLTYPE(CURSOR (SELECT
                                                 xmlelement("AGMT",
                                                           xmlelement("auditData"),                                        
                                                           xmlelement("AGMTID",h.AGMT_unq_id),
                                                                xmlelement("AGMTLevelValue", i.level_value),
                                                                xmlelement("AGMTSeqNbr", i.level_value),--not selected
                                                                xmlelement("nofication",
                                                                xmlelement("notificationId", i.notification_id),
                                                                     xmlelement("isNotifyInitiator", j.initiator_user_flag),
                                                                     xmlelement("isNotifyApprover", j.approver_user_flag),
                                                                     xmlelement("isNotifyReject", j.approver_user_flag),
                                                                     xmlelement("isNotifyCustomUsers", j.initiator_user_flag),
                                                                xmlelement("notifyCustomUsers",
                                                                     xmlelement("auditData"),
                                                                          xmlelement("notifyCustomId", k.notification_custom_id),
                                                                          xmlelement("role", xmlelement("roleId",k.role_id)),
                                                                          xmlelement("department", xmlelement("departmentId", k.department_id)),
                                                                          xmlelement("company", xmlelement("companyId", k.company_id)),
                                                                          xmlelement("division", xmlelement("divisionId", k.division_id))
                   FROM WORKFLOW_AGMT_TBL h,
                   AGMT_TBL i,
                   NOTIFC_TBL j,
                   NOTIFC_CUSTOMUSR_TBL k
                   WHERE h.workflow_unq_id = x.workflow_unq_id
                   AND h.AGMT_unq_id = i.AGMT_unq_id
                   AND i.notification_id = j.notification_id
                   AND j.notification_id = k.notification_id
                   )))--worflowAGMT                         
                   FROM WORKFLOW_TBL x, WF_WORKFLOW_TYPE y
                   WHERE y.workflow_type_id = x.workflow_type_id

    Hi,
    Most often, you get this type of error with CURSOR expression when it does not return any row, then the XMLType constructor fails.
    But it's hard to say here as you don't provide sample data.
    It looks like you want to aggregate rows coming from the CURSOR subquery. It's better to use XMLAgg function in this case.
    Something like :
    SELECT xmlelement("worflowAGMT",
            ( SELECT xmlagg(
                       xmlelement("AGMT",
    ...

  • Query or procedure reformatting xmltype (clob)

    help me out with this one, please. I have not been able to narrow it down:
    platform: Ora 9.2.0.5 on AIX, accessed remotely, character set AL32UTF8.
    Table with multiple of columns, 2 SYS.XMLTYPE columns (storage CLOB, not compiled schema (xsd:datetime timezone issues)).
    One column is a digitally signed xml doc; must be image consistent (char for char).
    test 1:
    select digitalsignedxml from table where ....;
    result is identical to input; life is good.
    test 2:
    select XMLeleement("digitallysigneddoc", digitallysignedxml) from table where ....;
    the body is still identical to the input (ignoring the wrapper), life is good.
    test3:
    same query as 2, but in a packaged function that is returning XMLTYPE.
    The body is not identical, but reformatted. sigh. life is not good.
    I have not been able to pin (narrow) this down. I have verified identical, not identical using sqlplus (set long 20000 linesize 20000 header off) and with the team's java application.
    ???

    The problem appears to be that "SELECT xmltype_column" from table (XMLTYPE on clob) returns the data as is with no reformatting, and "SELECT XML("wrapper", xmltype_column) from table will totally reformat the xml in the column. Even though the data is stored in CLOB, it is no longer image consistent. yeah, it is still DOM consistent, but if we are dealing with a digitally signed doc, then how can I include that digitally signed doc in a larger XML doc, and still have it valid?
    here are teh test cases:
    REM for posting purposes I put ";" at all eol (if not already there).
    environment: server 9.2.0.5 on AIX
    client: sqlplus 9.2.0.5.0 also on AIX (remote, not ORACLE_SID)
    set long 20000 linesize 20000 heading off
    def vxml1='<testDoc id="6734"> <authSignature><ds:Signature xmlns:ds="http://www
    .w3.org/2000/09/xmldsig#"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="h
    ttp://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>';
    def vxml2='<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-
    sha1"/><ds:Reference URI="testDoc"><ds:Transforms><ds:Transform Algorithm="http:
    //www.w3.org/TR/2001/REC-xml-c14n-20010315"/>';
    def vxml3='</ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09
    /xmldsig#sha1"/><ds:DigestValue>00OrCVzig5V9p5SLbjDXbryYZkQ=</ds:DigestValue></d
    s:Reference></ds:SignedInfo>';
    def vxml4='<ds:SignatureValue>foo</ds:SignatureValue><ds:KeyInfo><ds:KeyName>Pub
    lic key of certificate</ds:KeyName><ds:KeyValue><ds:RSAKeyValue>';
    def vxml5='<ds:Modulus>bar</ds:Modulus><ds:Exponent>AQAB</ds:Exponent></ds:RSAKe
    yValue></ds:KeyValue><ds:X509Data>';
    def vxml6='<ds:X509Certificate>data here</ds:X509Certificate></ds:X509Data></ds:
    KeyInfo></ds:Signature></authSignature></testDoc>';
    select xmltype('&vxml1.&vxml2.&vxml3.&vxml4.&vxml5.&vxml6') from dual;
    select XMLelement("testdoc",xmltype('&vxml1.&vxml2.&vxml3.&vxml4.&vxml5.&vxml6')
    ) from dual;
    results:
    15:25:43 dev58 SQL> select xmltype('&vxml1.&vxml2.&vxml3.&vxml4.&vxml5.&vxml6') from dual;
    <testDoc id="6734"> <authSignature><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><ds:Reference URI="testDoc"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>00OrCVzig5V9p5SLbjDXbryYZkQ=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>foo</ds:SignatureValue><ds:KeyInfo><ds:KeyName>Public key of certificate</ds:KeyName><ds:KeyValue><ds:RSAKeyValue><ds:Modulus>bar</ds:Modulus><ds:Exponent>AQAB</ds:Exponent></ds:RSAKeyValue></ds:KeyValue><ds:X509Data><ds:X509Certificate>data here</ds:X509Certificate></ds:X509Data></ds:KeyInfo></ds:Signature></authSignature></testDoc>
    1 row selected.
    Elapsed: 00:00:00.01
    15:25:43 dev58 SQL>
    15:25:43 dev58 SQL> select XMLelement("testdoc",xmltype('&vxml1.&vxml2.&vxml3.&vxml4.&vxml5.&vxml6')) from dual;
    <testdoc><testDoc id="6734">
    <authSignature>
    <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
    <ds:SignedInfo>
    <ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
    <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
    <ds:Reference URI="testDoc">
    <ds:Transforms>
    <ds:Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
    </ds:Transforms>
    <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
    <ds:DigestValue>00OrCVzig5V9p5SLbjDXbryYZkQ=</ds:DigestValue>
    </ds:Reference>
    </ds:SignedInfo>
    <ds:SignatureValue>foo</ds:SignatureValue>
    <ds:KeyInfo>
    <ds:KeyName>Public key of certificate</ds:KeyName>
    <ds:KeyValue>
    <ds:RSAKeyValue>
    <ds:Modulus>bar</ds:Modulus>
    <ds:Exponent>AQAB</ds:Exponent>
    </ds:RSAKeyValue>
    </ds:KeyValue>
    <ds:X509Data>
    <ds:X509Certificate>data here</ds:X509Certificate>
    </ds:X509Data>
    </ds:KeyInfo>
    </ds:Signature>
    </authSignature>
    </testDoc>
    </testdoc>
    1 row selected.
    Elapsed: 00:00:00.04
    REM REM hint: this is much stripped down bare bones of actual digitial signed xml doc ...

  • XMLType - client problem on reading XML?

    When I execute this function in my 9.2.0.7.0 database:
    create or replace function get_study_xml (p_study_id in number)
    return xmltype is xml_doc xmltype;
    begin
      execute immediate '
        select xmlelement(
          ...lots of code...
      from XML_STUDY_VIEW where STUDY_ID = '||p_study_id||'' into xml_doc;
    return xml_doc;
    end get_study_xml;I get the following error with a 9.2.0.1.0 client:
    ORA-03118: two-task coroutine has invalid stateAnd the following error with a 9.2.0.3.0 client:
    ORA-21500: internal error code, arguments: [%s], [%s], [%s], [%s], [%s], [%s], [%s], [%s]And finally the following error with a 9.2.0.7.0 client:
    ORA-24909: call in progress. Current operation cancelledI've done lots of investigation, and so far I've deduced the following:
    * It works fine on a PC with a 10g client
    * The function returns the XMLType successfully (it seems)
    * On all clients, the error occurs not on returning the XMLType, but on trying to read the XML within.
    I am trying to do this via Delphi components from Allround Automations (makers of PL/SQL Developer). I don't know how to output the XML to DBMS Output, so could do with some help there. If I could test it without using Allround's components, I could isolate the problem.
    I suspect the problem is not with the components though but with the OCI/client, because the same components work fine on 10g client.
    If someone could help give some suggestions, including how I could try to output the XML in SQL*Plus, it would be greatly appreciated.
    Best regards,
    Gary
    I don't know if it's relevent, but it may be worth noting that the SQL statement I've commented out is fairly massive, but even if I query data that produces a tiny XML object (i.e. hardly any data), it still fails. The full function is below, so you can see what I'm doing:
    create or replace function get_study_xml (p_study_id in number)
    return xmltype is xml_doc xmltype;
    begin
    execute immediate '
    select xmlelement(
      "STUDY",
      xmlforest(STUDY_ID, '||columnsforest('XML_STUDY_VIEW')||')
        select xmlagg(
          xmlelement(
            "STUDYHEADING",
            xmlforest('||columnsforest('XML_STUDYHEADING_VIEW')||')
        from XML_STUDYHEADING_VIEW where STUDY_ID = '||p_study_id||'
        select xmlelement(
          "TESTSUBSTANCE",
          xmlforest('||columnsforest('XML_TESTSUBSTANCE_VIEW')||')
        from XML_TESTSUBSTANCE_VIEW where STUDY_ID = '||p_study_id||'
        select xmlagg(
          xmlelement(
            "STRAIN",
            xmlforest('||columnsforest('XML_STRAIN_VIEW')||')
        from XML_STRAIN_VIEW where STUDY_ID = '||p_study_id||'
        select xmlagg(
          xmlelement(
            "POSITIVECONTROL",
            xmlforest('||columnsforest('XML_POSCTRL_VIEW')||')
        from XML_POSCTRL_VIEW where STUDY_ID = '||p_study_id||'
        select xmlagg(
          xmlelement(
            "SOLVENT",
            xmlforest('||columnsforest('XML_SOLVENT_VIEW')||')
        from XML_SOLVENT_VIEW where STUDY_ID = '||p_study_id||'
        select xmlagg(
          xmlelement(
            "POSTFIX",
            xmlforest('||columnsforest('XML_POSTFIX_VIEW')||')
        from XML_POSTFIX_VIEW where STUDY_ID = '||p_study_id||'
        select xmlagg(
          xmlelement(
            "EXPERIMENTFOLDER",
            xmlforest(FOLDER_ID,'||columnsforest('XML_EXPTFOLDER_VIEW')||'),(
              select xmlagg(
                xmlelement(
                  "EXPERIMENT",
                  xmlforest(EXPT_ID,'||columnsforest('XML_EXPERIMENT_VIEW')||'),(
                    select xmlagg(
                      xmlelement(
                        "EXPERIMENTHEADING",
                        xmlforest('||columnsforest('XML_EXPTHEADING_VIEW')||')
                    from XML_EXPTHEADING_VIEW h where h.EXPT_ID = e.EXPT_ID
                    select xmlagg(
                      xmlelement(
                        "EXPERIMENTSTRAIN",
                        xmlforest('||columnsforest('XML_EXPTSTRAIN_VIEW')||'),(
                          select xmlagg(
                            xmlelement(
                              "PLATE",
                              xmlforest('||columnsforest('XML_EXPTPLATE_VIEW')||'),(
                                select xmlagg(
                                  xmlelement("POSTFIX",CODE_ID)
                                from XML_PLATEPOSTFIX_VIEW x where x.PLATE_ID = p.PLATE_ID
                                and x.FOLDER_ID = f.FOLDER_ID
                          from XML_EXPTPLATE_VIEW p where p.EXPT_ID = e.EXPT_ID
                          and p.STRAIN_CODE = s.STRAIN_CODE
                          and p.PLATE_TYPE = 0                         
                    from XML_EXPTSTRAIN_VIEW s where s.EXPT_ID = e.EXPT_ID
              from XML_EXPERIMENT_VIEW e where e.STUDY_ID = '||p_study_id||'
              and f.folder_id = e.folder_id  
              select xmlagg(
                xmlelement(
                  "CONTROL",
                  xmlforest('||columnsforest('XML_CONTROL_VIEW')||'),(
                    select xmlagg(
                      xmlelement(
                        "CONTROLPLATE",
                        xmlforest('||columnsforest('XML_CONTROLPLATE_VIEW')||'),(
                          select xmlagg(
                            xmlelement("POSTFIX",CODE_ID)
                          from XML_PLATEPOSTFIX_VIEW x where x.PLATE_ID = p.PLATE_ID
                          and x.FOLDER_ID = f.FOLDER_ID
                    from XML_CONTROLPLATE_VIEW p where p.CONTROL_ID = c.CONTROL_ID
                    and p.PLATE_TYPE > 0
              from XML_CONTROL_VIEW c where c.STUDY_ID = '||p_study_id||'
              and f.folder_id = c.folder_id  
        from XML_EXPTFOLDER_VIEW f where f.STUDY_ID = '||p_study_id||'
    from XML_STUDY_VIEW where STUDY_ID = '||p_study_id||'' into xml_doc;
    return xml_doc;
    end get_study_xml;

    This may be related to bug 3396162 but I'm not sure I fully understand the implications of this bug, or the cirumstances under which it can arise.
    Getting back to the basic problem. Can you reproduce the problem with by calling your PL/SQL from a 9.2.0.7.0 SQL*PLUS.
    I'm not familar with Delphi. Is it Java or 'C' based. Is it using an OCI connection. If so does it bind to the latest Oracle Installation or does it embed the Oracle OCI components. If the later do you know which version of OCI is embedded ?
    WRT to dumping to DBMS_OUTPUT the following is a somewhat of a work in progress...
    create or replace package XDB_XML_OUTPUT_10200
    AUTHID CURRENT_USER
    as
      procedure put_xml(myXML XMLType);
      procedure processNode(INDENT VARCHAR2, NODE DBMS_XMLDOM.DOMNODE);
    end;
    create or replace package body XDB_XML_OUTPUT_10200
    as
      currentLine CLOB;
      wipBuffer CLOB;
      printBuffer CLOB;
      currentNode pls_integer;
      elementClosed boolean;
    procedure outputBuffer(buffer in out nocopy CLOB)
    as
    begin
      dbms_output.put_line(buffer);
      dbms_lob.trim(buffer,0);
    end;
    procedure putNode(INDENT varchar2, NODE DBMS_XMLDOM.DOMNODE)
    as
      byteCount pls_integer;
    begin
      if (currentNode = DBMS_XMLDOM.ELEMENT_NODE) then
        outputBuffer(currentLine);
      end if;
      byteCount := length(INDENT);
      dbms_lob.writeAppend(currentLine,byteCount,INDENT);
      dbms_lob.trim(printBuffer,0);
      dbms_xmldom.writeToCLOB(node,printBuffer);
      dbms_lob.append(currentLine,printBuffer);
    end; 
    procedure putAttribute(NODE DBMS_XMLDOM.DOMNODE)
    as
      buffer varchar2(32767);
      byteCount pls_integer;
    begin
      dbms_lob.trim(printBuffer,0);
      dbms_xmldom.writeToCLOB(node,printBuffer);
      dbms_lob.trim(wipBuffer,0);
      buffer := ' ' || DBMS_XMLDOM.GETNODENAME(NODE) || '="';
      byteCount := length(buffer);
      dbms_lob.writeAppend(wipBuffer,byteCount,buffer);
      dbms_lob.append(wipBuffer,printBuffer);
      byteCount := 1;
      dbms_lob.writeAppend(wipBuffer,byteCount,'"');
      dbms_lob.append(currentLine,wipBuffer);
    end; 
    procedure putAttributes(ATTRS DBMS_XMLDOM.DOMNAMEDNODEMAP)
    as
      ATTRNODE  DBMS_XMLDOM.DOMNODE;
    begin
      for i in 0..DBMS_XMLDOM.GETLENGTH(ATTRS)-1 loop
        ATTRNODE := DBMS_XMLDOM.ITEM(ATTRS,I);
        putAttribute(ATTRNODE);
      end loop;
    end;
    procedure printText(NODE DBMS_XMLDOM.DOMNODE)
    as
      byteCount pls_integer;
      buffer varchar2(1);
    begin
      buffer := '>';
      byteCount := length(buffer);
      dbms_lob.writeAppend(currentLine,byteCount,buffer);
      dbms_lob.trim(printBuffer,0);
      dbms_xmldom.writeToCLOB(NODE,printBuffer);
      dbms_lob.append(currentLine,printBuffer);
      currentNode := DBMS_XMLDOM.TEXT_NODE;
    end; 
    procedure startElement(INDENT varchar2, NODE DBMS_XMLDOM.DOMNODE, ATTRS DBMS_XMLDOM.DOMNAMEDNODEMAP)
    as
      byteCount pls_integer;
      buffer varchar2(32767);
    begin 
      if (not elementClosed) then
        buffer := '>';
        byteCount := 1;
        dbms_lob.writeAppend(currentLine,byteCount,buffer);
      end if;
      elementClosed := false;
      -- Start a new Element : Flush the buffer
      outputBuffer(currentLine);
      dbms_lob.trim(wipBuffer,0);
      buffer := INDENT || '<' || DBMS_XMLDOM.GETNODENAME(NODE);
      byteCount := length(buffer);
      dbms_lob.writeAppend(currentLine,byteCount,buffer);
      putAttributes(ATTRS);
      currentNode := DBMS_XMLDOM.ELEMENT_NODE;
    end;
    procedure endElement(INDENT varchar2, NODE DBMS_XMLDOM.DOMNODE)
    as
      byteCount pls_integer;
      buffer varchar2(32767);
    begin
      if (elementClosed) then
        outputBuffer(currentLine);
        buffer :=  INDENT || '</' || DBMS_XMLDOM.GETNODENAME(NODE) || '>';
        byteCount := length(buffer);
        dbms_lob.writeAppend(currentline,byteCount,buffer);
      else
        if (currentNode = DBMS_XMLDOM.ELEMENT_NODE) then
          buffer := '/>';
          byteCount := length(buffer);
          dbms_lob.writeAppend(currentline,byteCount,buffer);
        else
          buffer := '</' || DBMS_XMLDOM.GETNODENAME(NODE) || '>';
          byteCount := length(buffer);
          dbms_lob.writeAppend(currentline,byteCount,buffer);
        end if;
      end if;
      currentNode := DBMS_XMLDOM.ELEMENT_NODE;
      elementClosed := true;
    end;
    procedure processChildren(INDENT varchar2, NODE DBMS_XMLDOM.DOMNODE)   
    as
      CHILDREN DBMS_XMLDOM.DOMNODELIST;
      CHILD    DBMS_XMLDOM.DOMNODE;
    begin
      CHILDREN := DBMS_XMLDOM.GETCHILDNODES(NODE);
      for i in 0..DBMS_XMLDOM.GETLENGTH(CHILDREN)-1 loop
        CHILD  := DBMS_XMLDOM.ITEM(CHILDREN,I);
        processNode(INDENT , CHILD);
      end loop;
    end;
    procedure processNode(INDENT VARCHAR2, NODE DBMS_XMLDOM.DOMNODE)
    as
      newIndent varchar2(256) := INDENT || '  ';
    begin
      -- ENTITY_REFERENCE_NODE
      -- ENTITY_NODE
      -- DOCUMENT_TYPE_NODE
      -- DOCUMENT_FRAGMENT_NODE
      -- NOTATION_NODE
      if (DBMS_XMLDOM.GETNODETYPE(NODE) = DBMS_XMLDOM.COMMENT_NODE) then
        putNode(INDENT,NODE);
      end if;
      if (DBMS_XMLDOM.GETNODETYPE(NODE) = DBMS_XMLDOM.PROCESSING_INSTRUCTION_NODE ) then
        putNode(INDENT,NODE);
      end if;
      if (DBMS_XMLDOM.GETNODETYPE(NODE) = DBMS_XMLDOM.CDATA_SECTION_NODE) then
        putNode(INDENT,NODE);
      end if;
      if (DBMS_XMLDOM.GETNODETYPE(NODE) = DBMS_XMLDOM.TEXT_NODE) then
        printText(NODE);
      end if;
      if (DBMS_XMLDOM.GETNODETYPE(NODE) = DBMS_XMLDOM.ATTRIBUTE_NODE) then
        putAttribute(NODE);
      end if;
      if (DBMS_XMLDOM.GETNODETYPE(NODE) = DBMS_XMLDOM.ELEMENT_NODE) then
        startElement(INDENT,NODE,DBMS_XMLDOM.GETATTRIBUTES(NODE));
        processChildren(newIndent, NODE);
        endElement(INDENT,NODE);
      end if;
      if (DBMS_XMLDOM.GETNODETYPE(NODE) = DBMS_XMLDOM.DOCUMENT_NODE) then
        processChildren(INDENT,NODE);
      end if; 
    end;
    procedure put_xml(myXML XMLType)
    as
      doc DBMS_XMLDOM.DOMDOCUMENT;
    begin
      DBMS_LOB.createTemporary(currentLine,true,DBMS_LOB.SESSION);
      DBMS_LOB.createTemporary(wipBuffer,true,DBMS_LOB.SESSION);
      DBMS_LOB.createTemporary(printBuffer,true,DBMS_LOB.SESSION);
      doc := DBMS_XMLDOM.NEWDOMDOCUMENT(myXML);
      processNode('#',DBMS_XMLDOM.MAKENODE(doc));
      outputBuffer(currentLine);
      DBMS_LOB.freeTemporary(printBuffer);
      DBMS_LOB.freeTemporary(wipBuffer);
      DBMS_LOB.freeTemporary(currentLIne);
    end;
    end;
    /

Maybe you are looking for