Dbms_xmlquery.getxml problem

SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM --------- ---------- --------- ---------- --------- ---------- ---------- ---------- --------- ------------
7369 SMITH CLERK 7902 17-DEC-80 800 20
14 rows selected.
SQL> select dbms_xmlquery.getxml('select * from emp where rownum<2') from dual;
DBMS_XMLQUERY.GETXML('SELECT*FROMEMPWHEREROWNUM<2')
<?xml version = '1.0'?>
<ROWSET>
<ROW num="1">
<EMPNO>7369</EMPNO>
I'm just wondering why the query output XML has EMPNO alone, and not the other column data.Please help.
Thanks,
Bhagat

It's because of the parameter settings in SQL*Plus. It's just not showing the whole output for you...
SQL> select dbms_xmlquery.getxml('select * from emp where rownum<2') from dual;
DBMS_XMLQUERY.GETXML('SELECT*FROMEMPWHEREROWNUM<2')
<?xml version = '1.0'?>
<ROWSET>
   <ROW num="1">
      <EMPNO>7369</EMPNO>
SQL> set long 2000
SQL> select dbms_xmlquery.getxml('select * from emp where rownum<2') from dual;
DBMS_XMLQUERY.GETXML('SELECT*FROMEMPWHEREROWNUM<2')
<?xml version = '1.0'?>
<ROWSET>
   <ROW num="1">
      <EMPNO>7369</EMPNO>
      <ENAME>SMITH</ENAME>
      <JOB>CLERK</JOB>
      <MGR>7902</MGR>
      <HIREDATE>12/17/1980 0:0:0</HIREDATE>
      <SAL>800</SAL>
      <DEPTNO>20</DEPTNO>
   </ROW>
</ROWSET>
SQL>

Similar Messages

  • I need to pass a query in form of string to DBMS_XMLQUERY.GETXML package...the parameters to the query are date and varchar ..please help me..

    I need to pass a query in form of string to DBMS_XMLQUERY.GETXML package...the parameters to the query are date and varchar ..please help me build the string .Below is the query and the out put. ( the string is building fine except the parameters are with out quotes)
    here is the procedure
    create or replace
    procedure temp(
        P_MTR_ID VARCHAR2,
        P_FROM_DATE    IN DATE ,
        P_THROUGH_DATE IN DATE ) AS
        L_XML CLOB;
        l_query VARCHAR2(2000);
    BEGIN
    l_query:=  'SELECT
        a.s_datetime DATETIME,
        a.downdate Ending_date,
        a.downtime Ending_time,
        TO_CHAR(ROUND(a.downusage,3),''9999999.000'') kWh_Usage,
        TO_CHAR(ROUND(a.downcost,2),''$9,999,999.00'') kWh_cost,
        TO_CHAR(ROUND(B.DOWNUSAGE,3),''9999999.000'') KVARH
      FROM
        (SELECT s_datetime + .000011574 s_datetime,
          TO_CHAR(S_DATETIME ,''mm/dd/yyyy'') DOWNDATE,
          DECODE(TO_CHAR(s_datetime+.000011574 ,''hh24:'
          ||'mi''), ''00:'
          ||'00'',''24:'
          ||'00'', TO_CHAR(s_datetime+.000011574,''hh24:'
          ||'mi'')) downtime,
          s_usage downusage,
          s_cost downcost
        FROM summary_qtrhour
        WHERE s_mtrid = '
        ||P_MTR_ID||
       ' AND s_mtrch   = ''1''
        AND s_datetime BETWEEN TO_DATE('
        ||P_FROM_DATE||
        ',''DD-MON-YY'') AND (TO_DATE('
        ||P_THROUGH_DATE||
        ',''DD-MON-YY'') + 1)
        ) a,
        (SELECT s_datetime + .000011574 s_datetime,
          s_usage downusage
        FROM summary_qtrhour
        WHERE s_mtrid = '
        ||P_MTR_ID||
        ' AND s_mtrch   = ''2''
        AND s_datetime BETWEEN TO_DATE('
        ||P_FROM_DATE||
        ',''DD-MON-YY'') AND (TO_DATE('
        ||P_THROUGH_DATE||
        ','' DD-MON-YY'') + 1)
        ) B
      where a.S_DATETIME = B.S_DATETIME(+)';
    SELECT DBMS_XMLQUERY.GETXML('L_QUERY') INTO L_XML   FROM DUAL;
    INSERT INTO NK VALUES (L_XML);
    DBMS_OUTPUT.PUT_LINE('L_QUERY IS :'||L_QUERY);
    END;
    OUTPUT parameters are in bold (the issue is they are coming without single quotes otherwise th equery is fine
    L_QUERY IS :SELECT
        a.s_datetime DATETIME,
        a.downdate Ending_date,
        a.downtime Ending_time,
        TO_CHAR(ROUND(a.downusage,3),'9999999.000') kWh_Usage,
        TO_CHAR(ROUND(a.downcost,2),'$9,999,999.00') kWh_cost,
        TO_CHAR(ROUND(B.DOWNUSAGE,3),'9999999.000') KVARH
      FROM
        (SELECT s_datetime + .000011574 s_datetime,
          TO_CHAR(S_DATETIME ,'mm/dd/yyyy') DOWNDATE,
          DECODE(TO_CHAR(s_datetime+.000011574 ,'hh24:mi'), '00:00','24:00', TO_CHAR(s_datetime+.000011574,'hh24:mi')) downtime,
          s_usage downusage,
          s_cost downcost
        FROM summary_qtrhour
        WHERE s_mtrid = N3165 AND s_mtrch   = '1'
        AND s_datetime BETWEEN TO_DATE(01-JAN-13,'DD-MON-YY') AND (TO_DATE(31-JAN-13,'DD-MON-YY') + 1)
        ) a,
        (SELECT s_datetime + .000011574 s_datetime,
          s_usage downusage
        FROM summary_qtrhour
        WHERE s_mtrid = N3165 AND s_mtrch   = '2'
        AND s_datetime BETWEEN TO_DATE(01-JAN-13,'DD-MON-YY') AND (TO_DATE(31-JAN-13,' DD-MON-YY') + 1)
        ) B
      where a.S_DATETIME = B.S_DATETIME(+)

    The correct way to handle this is to use bind variables.
    And use DBMS_XMLGEN instead of DBMS_XMLQUERY :
    create or replace procedure temp (
      p_mtr_id       in varchar2
    , p_from_date    in date
    , p_through_date in date
    is
      l_xml   CLOB;
      l_query VARCHAR2(2000);
      l_ctx   dbms_xmlgen.ctxHandle;
    begin
      l_query:=  'SELECT
        a.s_datetime DATETIME,
        a.downdate Ending_date,
        a.downtime Ending_time,
        TO_CHAR(ROUND(a.downusage,3),''9999999.000'') kWh_Usage,
        TO_CHAR(ROUND(a.downcost,2),''$9,999,999.00'') kWh_cost,
        TO_CHAR(ROUND(B.DOWNUSAGE,3),''9999999.000'') KVARH
      FROM
        (SELECT s_datetime + .000011574 s_datetime,
          TO_CHAR(S_DATETIME ,''mm/dd/yyyy'') DOWNDATE,
          DECODE(TO_CHAR(s_datetime+.000011574 ,''hh24:'
          ||'mi''), ''00:'
          ||'00'',''24:'
          ||'00'', TO_CHAR(s_datetime+.000011574,''hh24:'
          ||'mi'')) downtime,
          s_usage downusage,
          s_cost downcost
        FROM summary_qtrhour
        WHERE s_mtrid = :P_MTR_ID
        AND s_mtrch   = ''1''
        AND s_datetime BETWEEN TO_DATE(:P_FROM_DATE,''DD-MON-YY'')
                           AND (TO_DATE(:P_THROUGH_DATE,''DD-MON-YY'') + 1)
        ) a,
        (SELECT s_datetime + .000011574 s_datetime,
          s_usage downusage
        FROM summary_qtrhour
        WHERE s_mtrid = :P_MTR_ID
        AND s_mtrch   = ''2''
        AND s_datetime BETWEEN TO_DATE(:P_FROM_DATE,''DD-MON-YY'')
                           AND (TO_DATE(:P_THROUGH_DATE,'' DD-MON-YY'') + 1)
        ) B
      where a.S_DATETIME = B.S_DATETIME(+)';
      l_ctx := dbms_xmlgen.newContext(l_query);
      dbms_xmlgen.setBindValue(l_ctx, 'P_MTR_ID', p_mtr_id);
      dbms_xmlgen.setBindValue(l_ctx, 'P_FROM_DATE', to_char(p_from_date, 'DD-MON-YY'));
      dbms_xmlgen.setBindValue(l_ctx, 'P_THROUGH_DATE', to_char(p_through_date, 'DD-MON-YY'));
      l_xml := dbms_xmlgen.getXML(l_ctx);
      dbms_xmlgen.closeContext(l_ctx);
      insert into nk values (l_xml);
    end;

  • Method DBMS_XMLQUERY.getXML() always inserts " ?xml version = '1.0'? " in output

    Method "SYS.DBMS_XMLQUERY.getXML()" seems to always want to prefix "<?xml version = '1.0'?>" to the returned output.
    I don't think this is always called for.
    I want to extract data from the database as an XML fragment. Outside of the RDBMS, I would then combine multiple fragments together into a larger XML document. If each fragment is prefixed with "<?xml version = '1.0'?>", I have to add logic to strip out this offending line.
    I tried method setXslt(). Even when my XSL stylesheet transforms the XML into HTML or TEXT, the output gets prefixed with "<?xml version = '1.0'?>", which I feel is wrong.
    Question: Is there any way to instruct DBMS_XMLQUERY to omit "<?xml version = '1.0'?>" ?
    Thanks!
    Louis

    Hi,
    Use DBMS_XMLGEN.getXMLType to retrieve the XML data into an XMLType variable.
    Then, with getClobVal method, you can convert it to CLOB :
    SQL> DECLARE
      2    v_xml XMLType;
      3    v_lob CLOB;
      4  BEGIN
      5    v_xml := dbms_xmlgen.getXMLType('select * from scott.emp where rownum = 1');
      6    v_lob := v_xml.getClobVal();
      7 
      8    dbms_output.put_line(v_lob);
      9  END;
    10  /
    <ROWSET>
    <ROW>
      <EMPNO>7369</EMPNO>
      <ENAME>SMITH</ENAME>
      <JOB>CLERK</JOB>
      <MGR>7902</MGR>
      <HIREDATE>17/12/80</HIREDATE>
      <SAL>800</SAL>
      <DEPTNO>20</DEPTNO>
    </ROW>
    </ROWSET>
    PL/SQL procedure successfully completed

  • PL/SQL & xmlgen.getXML problem

    Hi All.
    I am just starting to investigate options with regards to procedures which return the results of queries, in XML format.
    I have written the following function:
    CREATE OR REPLACE FUNCTION returnXML(id NUMBER) RETURN CLOB IS
    query VARCHAR2(100);
    BEGIN
    query := 'SELECT *
    FROM test_table
    WHERE id = '||id;
    RETURN xmlgen.getXML(query);
    END;
    I am then calling this as such:
    SQL> SELECT returnXML(1) FROM dual;
    My problem is that when I call this function, it seems to only produce some of the output ! ie. I get the XML header, first ROWSET and ROW tags, but then a number of chars further inot my output it stops ! I have also tried calling thsi function from within another PL/SQL block, and the same thing happens. No error is generated at all.
    Does anyone have any ideas, or has anyone seen this problem before ?
    Thanks,
    Kristian.

    It just might be that SQL Plus is not printing out all the contents of the CLOB.
    You can do:
    SQL> set LONG 1000
    and run your query again. Or you can create a function similar to this one (from Oracle XDK Documentation):
    CREATE OR REPLACE PROCEDURE printClobOut(result IN OUT NOCOPY CLOB) is
    xmlstr varchar2(32767);
    line varchar2(2000);
    begin
    xmlstr := dbms_lob.SUBSTR(result,32767);
    loop
    exit when xmlstr is null;
    line := substr(xmlstr,1,instr(xmlstr,chr(10))-1);
    dbms_output.put_line('| '||line);
    xmlstr := substr(xmlstr,instr(xmlstr,chr(10))+1);
    end loop;
    end;
    To use:
    set serveroutput on
    declare
    result CLOB;
    begin
    -- get the result
    result := returnXML(<some ID>);
    -- print the result
    printClobOut(result);
    end;

  • Problem with generating xml and nested cursor (ora-600)

    I have a problem with generating xml (with dbms_xmlquery or xmlgen) and nested cursors.
    When I execute the following command, I get a ORA-600 error:
    select dbms_xmlquery.getxml('select mst_id
    , mst_source
    , cursor(select per.*
    , cursor(select ftm_fdf_number
    , ftm_value
    from t_feature_master
    where ftm_mstr_id = pers_master_id ) as features
    from t_person per
    where pers_master_id = mst_id ) as persons
    from f_master
    where mst_id = 3059435')
    from dual;
    <?xml version = '1.0'?>
    <ERROR>oracle.xml.sql.OracleXMLSQLException: ORA-00600: internal error code, arguments: [kokbnp2], [1731], [], [], [], [], [], []
    </ERROR>
    The problem is the second cursor (t_feature_master).
    I want to generate this:
    <master>
    <..>
    <persons>
    <..>
    <features>
    <..>
    </features>
    </persons>
    <persons>
    <..>
    <features>
    <..>
    </features>
    </persons>
    </master>
    If i execute the select-statement in sql-plus, then I get the next result.
    MST_ID MST_SOURCE PERSONS
    3059435 GG CURSOR STATEMENT : 3
    CURSOR STATEMENT : 3
    PERS_MASTER_ID PERS_TITLE PERS_INITI PERS_FIRSTNAME PERS_MIDDL PERS_LASTNAME
    3059435 W. Name
    CURSOR STATEMENT : 15
    FTM_FDF_NUMBER FTM_VALUE
    1 [email protected]
    10 ....
    I use Oracle 8.1.7.4 with Oracle XDK v9.2.0.5.0.
    Is this a bug and do somebody know a workaround?

    Very simple...Drop all type objects and nested tables and create them again. You will get no error. I'll explain the reason later.

  • Problem for xml generation using DBMS_XMLGEN

    Hi All,
    i have problem during xml generation using Any help would be highly appreciate
    how could we publish xml data using data base API DBMS_XMLGEN in oracle applications (APPS) i.e. at 'View Output" using
    Any help would be highly appreciate.
    Let me know if need more explanation, this is High priority for me.
    Thanks and Regards,
    [email protected]
    Message was edited by:
    user553699

    You can set the null attribute to true , so that the tag appears in your XML
    see the statement in Bold.
    DECLARE
    queryCtx dbms_xmlquery.ctxType;
    result CLOB;
    BEGIN
    -- set up the query context
    queryCtx := dbms_xmlquery.newContext(
    'SELECT empno "EMP_NO"
    , ename "NAME"
    , deptno "DEPT_NO"
    , comm "COMM"
    FROM scott.emp
    WHERE deptno = :DEPTNO'
    dbms_xmlquery.setRowTag(
    queryCtx
    , 'EMP'
    dbms_xmlquery.setRowSetTag(
    queryCtx
    , 'EMPSET'
    DBMS_XMLQUERY.useNullAttributeIndicator(queryCtx,true);
    dbms_xmlquery.setBindValue(
    queryCtx
    , 'DEPTNO'
    , 30
    result := dbms_xmlquery.getXml(queryCtx);
    insert into clobtable values(result);commit;
    dbms_xmlquery.closeContext(queryCtx);
    END;
    select * from clobtable
    <?xml version = '1.0'?>
    <EMPSET>
    <EMP num="1">
    <EMP_NO>7499</EMP_NO>
    <NAME>ALLEN</NAME>
    <DEPT_NO>30</DEPT_NO>
    <COMM>300</COMM>
    </EMP>
    <EMP num="2">
    <EMP_NO>7521</EMP_NO>
    <NAME>WARD</NAME>
    <DEPT_NO>30</DEPT_NO>
    <COMM>500</COMM>
    </EMP>
    <EMP num="3">
    <EMP_NO>7654</EMP_NO>
    <NAME>MARTIN</NAME>
    <DEPT_NO>30</DEPT_NO>
    <COMM>1400</COMM>
    </EMP>
    <EMP num="4">
    <EMP_NO>7698</EMP_NO>
    <NAME>BLAKE</NAME>
    <DEPT_NO>30</DEPT_NO>
    <COMM NULL="YES"/>
    </EMP>
    <EMP num="5">
    <EMP_NO>7844</EMP_NO>
    <NAME>TURNER</NAME>
    <DEPT_NO>30</DEPT_NO>
    <COMM>0</COMM>
    </EMP>
    <EMP num="6">
    <EMP_NO>7900</EMP_NO>
    <NAME>JAMES</NAME>
    <DEPT_NO>30</DEPT_NO>
    <COMM NULL="YES"/>
    </EMP>
    </EMPSET>
    http://sqltech.cl/doc/oracle9i/appdev.901/a89852/d_xmlque.htm

  • "Missing IN or OUT parameter at index:: 1" - dbms_xmlquery vs dbms_xmlgen

    It looks like DBMS_XMLQuery doesn't like bind variables among selected columns.
    While DBMS_XMLGEN handles them without any problems.
    A simple example:
    -- xml query - fails
    declare
    ctx dbms_xmlquery.ctxHandle;
    begin
    ctx := dbms_xmlquery.newContext(
    'select a.*, :r_max the_end from scott.emp a where rownum <= :r_max');
    dbms_xmlquery.setBindValue(ctx, 'r_max', 10);
    dbms_output.put_line(dbms_xmlquery.getxml(ctx));
    dbms_xmlquery.closeContext(ctx);
    end;
    The error is <ERROR>oracle.xml.sql.OracleXMLSQLException: Missing IN or OUT parameter at index:: 1</ERROR>
    -- xml gen - works
    declare
    ctx dbms_xmlgen.ctxHandle;
    begin
    ctx := dbms_xmlgen.newContext(
    'select a.*, :r_max the_end from scott.emp a where rownum <= :r_max');
    dbms_xmlgen.setBindValue(ctx, 'r_max', 10);
    dbms_output.put_line(dbms_xmlgen.getxml(ctx));
    dbms_xmlgen.closeContext(ctx);
    end;
    Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - Prod

    Looks like you need two binds to accomplish your task:
    SQL> declare
      2     ctx   dbms_xmlquery.ctxhandle;
      3  begin
      4     ctx := dbms_xmlquery.newcontext('select emp.*, :r_max1 the_end from emp where rownum <= :r_max2');
      5     dbms_xmlquery.setbindvalue (ctx, 'r_max1', 4);
      6     dbms_xmlquery.setbindvalue (ctx, 'r_max2', 4);
      7     dbms_output.put_line (dbms_xmlquery.getxml (ctx));
      8     dbms_xmlquery.clearbindvalues (ctx);
      9     dbms_xmlquery.closecontext (ctx);
    10  end;
    11  /
    PL/SQL procedure successfully completed.
    SQL> set serverout on
    SQL> /
    <?xml version = '1.0'?>
    <ROWSET>
       <ROW num="1">
          <EMPNO>7369</EMPNO>
    <ENAME>SMITH</ENAME>
          <JOB>CLERK</JOB>
          <MGR>7902</MGR>
    <HIREDATE>12/17/1980 0:0:0</HIREDATE>
          <SAL>800</SAL>
    <DEPTNO>20</DEPTNO>
          <THE_END>4</THE_END>
       </ROW>
       <ROW num="2">
    <EMPNO>7499</EMPNO>
          <ENAME>ALLEN</ENAME>
          <JOB>SALESMAN</JOB>
    <MGR>7698</MGR>
          <HIREDATE>2/20/1981 0:0:0</HIREDATE>
    <SAL>1600</SAL>
          <COMM>300</COMM>
          <DEPTNO>30</DEPTNO>
    <THE_END>4</THE_END>
       </ROW>
       <ROW num="3">
          <EMPNO>7521</EMPNO>
    <ENAME>WARD</ENAME>
          <JOB>SALESMAN</JOB>
          <MGR>7698</MGR>
    <HIREDATE>2/22/1981 0:0:0</HIREDATE>
          <SAL>1250</SAL>
    <COMM>500</COMM>
          <DEPTNO>30</DEPTNO>
          <THE_END>4</THE_END>
       </ROW>
    <ROW num="4">
          <EMPNO>7566</EMPNO>
          <ENAME>JONES</ENAME>
    <JOB>MANAGER</JOB>
          <MGR>7839</MGR>
          <HIREDATE>4/2/1981
    0:0:0</HIREDATE>
          <SAL>2975</SAL>
          <DEPTNO>20</DEPTNO>
    <THE_END>4</THE_END>
       </ROW>
    </ROWSET>
    PL/SQL procedure successfully completed.

  • UTF8 problem with XMLGEN

    Hi All,
    I'm having problems with the XML generation. The problem is that when we try to generate XML using a query, such as:
    select xmlgen.getXML('select content_id, locale_id, content from bc_content_local where delete_p = ''0''',1) from dual;
    It works fine so long as of the information retrieved by the query is ASCII. But if there are UTF8 characters in there, the
    generation of the XML fails.
    I wasn't actually getting an error message. It would work and return XML but as soon as the first UTF-8 character was encountered,
    the XML just stopped.
    Two questions:
    1) Does the XML generation support UTF-8? 2)
    If it does (I seem to remember hearing that it did) what has to be done so that this
    works correctly?
    We are using a UTF8 characterset we set during database creation. I have also tried setting up NLS_LANG in the client registrty to american_america.utf8 - but in both client and server I get teh same message.
    Database: Oracle 8.1.7 Standard Edition on Sun-Solaris 2.8
    Any help greatly appreciated,
    Nilendu Misra
    [email protected]

    Ok, I found we have DBMS_XMLQUERY installed on the schema other than SYS too. But when I issue the same statement using this package I get a different error:
    SQL> select dbms_xmlquery.getXML('select content_id, locale_id, content
    2 from bc_content_local where delete_p = ''0''',1) from dual;
    select dbms_xmlquery.getXML('select content_id, locale_id, content
    ERROR at line 1:
    ORA-29532: Java call terminated by uncaught Java exception:
    java.lang.NullPointerException
    ORA-06512: at "SYSTEM.DBMS_XMLQUERY", line 212
    ORA-06512: at "SYSTEM.DBMS_XMLQUERY", line 220
    ORA-06512: at "SYSTEM.DBMS_XMLQUERY", line 210
    ORA-06512: at "SYSTEM.DBMS_XMLQUERY", line 228
    ORA-06512: at line 1
    I tried searching the XML forum and Metalink but I found most of the reports on this nature of problem are still unanswered.
    Thanks in appreciation,
    Nilendu
    null

  • DBMS_XMLQUERY

    I have downloaded the tar xdk_plsql_9_0_1_0_0.tar file and installed
    the XDK onto my 8.1.7.2 database on a sun sparc server.
    My problem is this , for the user scott the following statement works fine in that it produces the xml output :
    select dbms_xmlquery.getxml('select * from emp', 2) from dual;
    However when I try to use the same package above as another user trying to generate xml on one of its tables , I get the following error:
    ORA-06502: PL/SQL: numeric or value error: character to number conversion error
    Both user scott and my "test user" have identical privileges, which includes the
    JAVASYSPRIV and the JAVAUSERPRIV.
    My question is this what do I have to do in order for another user to be able to use the
    dbms_xmlquery without getting any problems?

    RTFM.
    Function DBMS_XMLQUERY.GETXML takes 2 number parameters and returns a CLOB.
    If you do a describe on DBMS_XMLQUERY you will find :
    FUNCTION GETXML RETURNS CLOB
    Argument Name Type In/Out Default?
    CTX NUMBER IN
    METATYPE NUMBER IN DEFAULT
    You have to call DBMS_XMLQUERY.NEWCONTEXT and pass it the SQL statement. This function returns a CONTEXT ( number ) which you use in DBMS_XMLQUERY.GETXML.

  • DBMS_XMLQuery.setXSLT in XSU111 ver1_2_1 for Oracle 8.1.5

    Hi, All
    the problem is:
    im using XSU111 ver1_2_1 for Oracle 8.1.5
    below is some example whish throws an Error in SQL-Plus
    (ORA-03113: end-of-file on communication channel)
    when commented line is on
    -- ++++ start of script ++++
    create or replace function xsl_test return CLOB is
    queryCtx DBMS_XMLquery.ctxType;
    result CLOB := null;
    result1 CLOB := null;
    begin
    queryCtx := DBMS_XMLQuery.newContext('select * from airport where rownum < 10');
    --this line throws an Error DBMS_XMLQuery.setXSLT(queryCtx, 'http://localhost/xml/rowcol.xsl');
    result := DBMS_XMLQuery.getXML(queryCtx);
    DBMS_XMLQuery.closeContext(queryCtx);
    return result;
    end;
    select xsl_test from dual;
    -- ++++ end of script ++++
    null

    8.1.5 went out of support on dec 31, 2000,
    you will need to upgrade to a supported version to get any fixes for problems.

  • Need help please DBMS_XMLQUERY

    Hello ,
    i am trying to generate a xml in a db orcle 9i release Release 9.0.1.4.0 so i don not have many of the new functionality
    the code i am trying to execute is the foolowing
    DECLARE
    p_entityid LONG;
    p_entitylegalname VARCHAR2(100);
    p_businesstradenameone VARCHAR2(100);
    p_businesstradenametwo VARCHAR2(100);
    p_businesstradenamethree VARCHAR2(100);
    p_dunsnumber NUMBER;
    queryctx DBMS_XMLQUERY.ctxtype;
    RESULT CLOB;
    BEGIN
    queryctx :=
    SYS.DBMS_XMLQUERY.newcontext
    ('select :p_EntityID EntityID, :p_EntityLegalName EntityLegalName ,
    cursor( select :p_BankAccountID BankAccountID ,
    :p_BankCode BankCode
    from dual ana) AS dt
    from dual ana');
    SYS.DBMS_XMLQUERY.setrowsettag(queryctx, 'CreateEntityRequest');
    SYS.DBMS_XMLQUERY.setrowtag(queryctx, 'Entity');
    SYS.DBMS_XMLQUERY.setbindvalue(queryctx, 'p_EntityID', 1);
    SYS.DBMS_XMLQUERY.setbindvalue(queryctx, 'p_EntityLegalName', ' prueba');
    SYS.DBMS_XMLQUERY.setbindvalue(queryctx, 'p_BankAccountID', 23);
    SYS.DBMS_XMLQUERY.setbindvalue(queryctx, 'p_BankCode', '123');
    RESULT := SYS.DBMS_XMLQUERY.getxml(queryctx);
    printclobout(RESULT);
    SYS.DBMS_XMLQUERY.closecontext(queryctx);
    END;
    these give me the following xml
    | <?xml version = '1.0'?>
    | <CreateEntityRequest>
    | <Entity num="1">
    | <ENTITYID>1</ENTITYID>
    | <ENTITYLEGALNAME> prueba</ENTITYLEGALNAME>
    | <DT>
    | <DT_ROW num="1">
    | <BANKACCOUNTID>23</BANKACCOUNTID>
    | <BANKCODE>123</BANKCODE>
    | </DT_ROW>
    | </DT>
    | </Entity>
    | </CreateEntityRequest>
    the problem that i have is it writes this tag <DT_ROW num="1"> that i do not want an also it puts in the tag <Entity num="1"> the num="1"
    does sono one know how remove it
    i am desperate many thanks
    ana

    Hello
    I've read about the same problem on different places and everyone provides an alternative instead of the real solution.
    After reading soms specs on the Oracle website, I found this simple solution:
    dbms_xmlquery.setrowidattrname(query_ctx, NULL); -- default num
    dbms_xmlquery.setrowidattrvalue(query_ctx, NULL);
    Simply clear the default attribute (which is a constant of xmlquery) and it's value and you are set.
    Kind Regards
    Bjorn Ongenae
    iAdvise Consulting

  • Error using DBMS_XMLQuery() with XMLElement().

    Select dbms_xmlquery.getXML('Select SYS_XMLAGG(
      2                                     XMLElement("SDI",
      3                                                 active_flag)) ' ||
      4                              'from Sdi s where s.sdi_num = 22261')
      5* From Dual
    SQL> /
    DBMS_XMLQUERY.GETXML('SELECTSYS_XMLAGG(XMLELEMENT("SDI",ACTIVE_FLAG))'||'FROMSDI
    <?xml version = '1.0'?>
    <ERROR>oracle.xml.sql.OracleXMLSQLException: Character
    ')' is not allowed in an XML tag name.</ERROR>
    SQL>

    please help.
    This is urgent
    No offence meant
    ~
    ~
    ~
    ~
    ~
    Select dbms_xmlquery.getXML('Select SYS_XMLAGG(
                                        XMLElement("SDI",
                                                  active_flag) )  ' ||
                                'from Sdi s where s.sdi_num = 22261')
    From Dual
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    Select dbms_xmlquery.getXML('Select SYS_XMLAGG(
                                        XMLElement("SDI",
                                                  active_flag) ) ppp ' ||
                                'from Sdi s where s.sdi_num = 22261')
    From Dual
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    Select dbms_xmlquery.getXML('Select SYS_XMLAGG(
                                        XMLElement("SDI",
                                                  active_flag) )  ' ||
                                'from Sdi s where s.sdi_num = 22261')
    From Dual
    ~
    ~
    ~
    ~
    Select dbms_xmlquery.getXML('Select SYS_XMLAGG(
                                        XMLElement('||"S^?,
                                                  active_flag) )  ' ||
                                'from Sdi s where s.sdi_num = 22261')
    From Dual
    ~
    ~
    ~
    Select dbms_xmlquery.getXML('Select SYS_XMLAGG(
                                        XMLElement("SDI",
                                                  active_flag) )  ' ||
                                'from Sdi s where s.sdi_num = 22261')
    From Dual
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    Select dbms_xmlquery.getXML('Select SYS_XMLAGG(
                                        XMLElement("SDI",
                                                  active_flag) )  ' ||
                                'from Sdi s where s.sdi_num = 22261')
    From Dual
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    Select DBMS_XMLQuery.getXML('Select ' ||
    'SYS_XMLAGG(XMLElement(NULL,active_flag)) ' ||
    'FROM SDI S where S.sdi_num = 22261 ')
    FROM DUAL
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    Select DBMS_XMLQuery.getXML('Select ' ||
    'SYS_XMLAGG(XMLElement(S,active_flag)) ' ||
    'FROM SDI S where S.sdi_num = 22261 ')
    FROM DUAL
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    Select DBMS_XMLQuery.getXML('Select ' ||
    'SYS_XMLAGG(XMLElement(S, active_flag)) ' ||
    'FROM SDI S where S.sdi_num = 22261 ')
    FROM DUAL
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    Select DBMS_XMLQuery.getXML('Select ' ||
    'SYS_XMLAGG(XMLElement("S", active_flag)) ' ||
    'FROM SDI S where S.sdi_num = 22261 ')
    FROM DUAL
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    Select DBMS_XMLQuery.getXML('Select ' ||
    'SYS_XMLAGG(XMLElement("S", active_flag)) ' ||
    'FROM SDI S where S.sdi_num = 22261 ')
    FROM DUAL
    ~
    ~
    ~
    Select DBMS_XMLQuery.getXML('Select ' ||
    'SYS_XMLAGG(XMLElement("S", active_flag)) ' ||
    'FROM SDI S where S.sdi_num = 22261 ')
    FROM DUAL
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    :q
      1  Select DBMS_XMLQuery.getXML('Select ' ||
      2  'SYS_XMLAGG(XMLElement("SDI", active_flag)) ' ||
      3  'FROM SDI S where S.sdi_num = 22261 ')
      4* FROM DUAL
    SQL> /
    DBMS_XMLQUERY.GETXML('SELECT'||'SYS_XMLAGG(XMLELEMENT("S",ACTIVE_FLAG))'||'FROMS
    <?xml version = '1.0'?>
    <ERROR>oracle.xml.sql.OracleXMLSQLException: Character
    ')' is not allowed in an XML tag name.</ERROR>
    SQL>
    same error
    AM I OVERLOOKING SOMETHING? DOES DBMS_XMLQUERY() NOT SUPPORT
    XMLFOREST()?

  • XML Generation Using  DBMS_XMLQuery

    Hi,
    I am generating XML using "DBMS_XMLQuery".
    Requirement: To generate blank xml tag(Without data).
    e.g : Table XXX has A,B,C,D columns.
    I am using SQL : SELECT a AA,b BB,c CC,d DD FROM XXX;
    <AA>1 </AA>
    <BB>2 </BB>
    <CC>3 </CC>
    (Note : Columns A,B and C has Values but "d" column does not have value).
    Since "D" column doesnot have value,it is not generating XML tag.
    So ,How to generate XML tag(e.g <DD> </DD>) without Value?
    Any idea,how to achieve the above?
    Thanks in advance.
    Rgds,
    Manoj
    ==========================
    <?xml version = '1.0'?>
    <ORDERS>
    <ORDER num="1">
    <MESSAGE_ID>1</MESSAGE_ID>
    <SOURCE_SYSTEM>Oracle</SOURCE_SYSTEM>
    <OPERATION>OrderRMA</OPERATION>
    <DATETIME>3/21/2006 15:30:44</DATETIME>
    <VERSION>1</VERSION>
    <COUNTRY>AUS</COUNTRY>
    <LANGUAGE>ENG</LANGUAGE>
    <DESTINATION_SYSTEM>Manhattan</DESTINATION_SYSTEM>
    <DESTINATION_WAREHOUSE>AUSVIS</DESTINATION_WAREHOUSE>
    <ORDER_HEADER>
    <ORDER_HEADER_ROW num="1">
    ----

    You can set the null attribute to true , so that the tag appears in your XML
    see the statement in Bold.
    DECLARE
    queryCtx dbms_xmlquery.ctxType;
    result CLOB;
    BEGIN
    -- set up the query context
    queryCtx := dbms_xmlquery.newContext(
    'SELECT empno "EMP_NO"
    , ename "NAME"
    , deptno "DEPT_NO"
    , comm "COMM"
    FROM scott.emp
    WHERE deptno = :DEPTNO'
    dbms_xmlquery.setRowTag(
    queryCtx
    , 'EMP'
    dbms_xmlquery.setRowSetTag(
    queryCtx
    , 'EMPSET'
    DBMS_XMLQUERY.useNullAttributeIndicator(queryCtx,true);
    dbms_xmlquery.setBindValue(
    queryCtx
    , 'DEPTNO'
    , 30
    result := dbms_xmlquery.getXml(queryCtx);
    insert into clobtable values(result);commit;
    dbms_xmlquery.closeContext(queryCtx);
    END;
    select * from clobtable
    <?xml version = '1.0'?>
    <EMPSET>
    <EMP num="1">
    <EMP_NO>7499</EMP_NO>
    <NAME>ALLEN</NAME>
    <DEPT_NO>30</DEPT_NO>
    <COMM>300</COMM>
    </EMP>
    <EMP num="2">
    <EMP_NO>7521</EMP_NO>
    <NAME>WARD</NAME>
    <DEPT_NO>30</DEPT_NO>
    <COMM>500</COMM>
    </EMP>
    <EMP num="3">
    <EMP_NO>7654</EMP_NO>
    <NAME>MARTIN</NAME>
    <DEPT_NO>30</DEPT_NO>
    <COMM>1400</COMM>
    </EMP>
    <EMP num="4">
    <EMP_NO>7698</EMP_NO>
    <NAME>BLAKE</NAME>
    <DEPT_NO>30</DEPT_NO>
    <COMM NULL="YES"/>
    </EMP>
    <EMP num="5">
    <EMP_NO>7844</EMP_NO>
    <NAME>TURNER</NAME>
    <DEPT_NO>30</DEPT_NO>
    <COMM>0</COMM>
    </EMP>
    <EMP num="6">
    <EMP_NO>7900</EMP_NO>
    <NAME>JAMES</NAME>
    <DEPT_NO>30</DEPT_NO>
    <COMM NULL="YES"/>
    </EMP>
    </EMPSET>
    http://sqltech.cl/doc/oracle9i/appdev.901/a89852/d_xmlque.htm

  • XML/XSL parser/processor problem

    Can anyone telle why mij code doesn't work
    DECLARE
    XMLdoc CLOB;
    XSLdoc sys.xslprocessor.stylesheet;
    HTMLdoc CLOB;
    HTMLparser sys.xmlparser.parser;
    XSLprocessor sys.xslprocessor.processor;
    DOMdoc sys.xmldom.DOMdocument;
    queryCtx DBMS_XMLquery.ctxType;
    BEGIN
    queryCtx := DBMS_XMLQuery.newContext('select * from scott.emp');
    XMLdoc := DBMS_XMLQuery.getXML(queryCtx);
    DBMS_XMLQuery.closeContext(queryCtx);
    HTMLparser := sys.xmlparser.newparser;
    XSLprocessor := sys.xslprocessor.newprocessor;
    sys.xmlparser.parseclob(HTMLparser,XMLdoc);
    DOMdoc := sys.xmlparser.getdocument(HTMLparser);
    XSLdoc := sys.xslprocessor.newstylesheet(DOMdoc,'http://www.w3.org/TR/WD-xsl');
    sys.xslprocessor.processxsl(XSLprocessor,XSLdoc,DOMdoc,HTMLdoc);
    sys.xslprocessor.freestylesheet(XSLdoc);
    sys.xslprocessor.freeprocessor(XSLprocessor);
    sys.xmlparser.freeparser(HTMLparser);
    END;
    there should be html-output but it gives a error:
    ora-20100 attribute "xsl:version" not found in ROWSET......
    Can anyone help me get this code to wrk
    null

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Steven Muench ([email protected]):
    It appears that you're trying to use the result of the GETXML() -- which is some XML like <ROWSET>/<ROW> -- as the stylesheet itself.<HR></BLOCKQUOTE>
    but the function XSLdoc := sys.xslprocessor.newstylesheet(DOMdoc,'http://www.w3.org/TR/WD-xsl');
    makes a xsl from a xmldom object or am I wrong in this assumption.
    How would I do it then
    null

  • Result := dbms_xmlsquery.getXml(queryCtx);  1 row only is returned.

    I get only one record returned. The following code is taken from my block
    -- set up the query context...!
    queryCtx := DBMS_XMLQuery.newContext(l_stmt_sel || 'pris.' || l_table || '@rel ' );
    -- DBMS_XMLQuery.setRowTag(queryCtx,'???'); -- sets the row tag name
    DBMS_XMLQuery.setRowSetTag(queryCtx,l_table ); -- sets rowset tag name
    --DBMS_XMLQuery.setMaxRows(queryCtx,2);
    -- get the result..!
    result := DBMS_XMLQuery.getXML(queryCtx);
    -- Now you can use the result to put it in tables/send as messages..
    printClobOut(result);
    DBMS_XMLQuery.closeContext(queryCtx); -- you must close the query handle.
    the table has two rows in it.
    Result set when setmaxrows = 1
    DBMS_XMLQuery.setMaxRows(queryCtx,1);
    | <?xml version = '1.0'?>
    | <X_HOUSING_V>
    | <ROW num="1">
    | <HOU_BOOKNO>1564922</HOU_BOOKNO>
    | <HOU_ENTNO>2</HOU_ENTNO>
    | <HOU_ENT_DATE>11/8/2007 17:17:0</HOU_ENT_DATE>
    | <HOU_ENT_TIME>1717</HOU_ENT_TIME>
    | <HOU_ENT_OPER>S01072</HOU_ENT_OPER>
    | <HOU_FAC>C</HOU_FAC>
    | <HOU_TIER>01A</HOU_TIER>
    | <HOU_BED>020</HOU_BED>
    | <HOU_AUTH_OFF>S01072</HOU_AUTH_OFF>
    | <HOU_BEGIN_DATE>11/8/2007 17:17:0</HOU_BEGIN_DATE>
    | <HOU_BEGIN_TIME>1717</HOU_BEGIN_TIME>
    | <HOU_REASON>BI</HOU_REASON>
    | <HOU_TIER_COMMENT>1564922 DNGRM TX 12-18</HOU_TIER_COMMENT>
    | </ROW>
    | </X_HOUSING_V>
    when max rows is removed i get the following error.
    --DBMS_XMLQuery.setMaxRows(queryCtx,1);
    BEGIN
    | <?xml version = '1.0'?>
    | <ERROR>oracle.xml.sql.OracleXMLSQLException:
    java.lang.ArrayIndexOutOfBoundsException</ERROR>
    PL/SQL procedure successfully completed.
    when max rows is set to 2 i get the following error.
    DBMS_XMLQuery.setMaxRows(queryCtx,2);
    | <?xml version = '1.0'?>
    | <ERROR>oracle.xml.sql.OracleXMLSQLException:
    java.lang.ArrayIndexOutOfBoundsException</ERROR>
    PL/SQL procedure successfully completed.

    thank you for your reply sir !
    i am running the query in Keeptool 9. and am getting this output in the DBMS Output window.
    and secondly even if the output window is unable to show it, at least the table should save the contents right. But the contents of table are also not well formed xml as it contains invalid characters.
    all at loss :-s

Maybe you are looking for

  • Regular Expressions and Full-text Requests.

    Hi, i have just read that Berkeley DB XML doesnt support regexp in XQuery (what a pity), do you know how to look-alike regular expressions in Query? for example, i'd like to perform a full-text request, all tags that contains text like "Be.+ley" (it

  • Lightroom 3.5 - Library automatic syncing between two Macs?

    Hey there you Lightroom-Masters! I am diggin' deeper and deeper into Professional Photography and am now using two Macs two develop my my .DNG RAWs. In my Livingroom stands a 27" iMac, which is great to develop them further, and when I am on the road

  • Upgrade 11.5.10.2 to R12 on apps tier only

    Hussein, My Oracle EBS running on Split Tier architecture, 11.5.10.2 apps tier on sun server and 11.2.0.3 on Linux server. I am planning to upgrade R12. OATM is completed on the database server. Which is the best way to upgrade. As of now my option i

  • ORACLE error 29282 in FDPSTP

    hi i have this code with me ,a custom code which wrked fine till i added few lines of code for sequence number generation(eg 2010-0001, ie YYYY-xxxx format) CREATE OR REPLACE PROCEDURE Nap_Create_Job (ERRBUF OUT VARCHAR2,RETCODE OUT NUMBER,P_Job_Numb

  • Degradation in image sharpness in LR 2.7 64

    I am running LR 2.7 64 bit on Windows and experiencing an odd behavior regarding degradation of image sharpness over increased access. For example, I will transfer images from a shoot and begin my first pass review process. That process looks at a nu