DBMS_XMLGen.newContext giving ORA_19206

Greetings All,
I am trying to create xml output for a query with where clause as follows.
SELECT *
FROM employees
WHERE name = 'JEFF'
v_ctx = DBMS_XMLGen.newContext(
                       'SELECT *
                        FROM employees
                        WHERE name = ''JEFF''
[pre]             
WHERE name = ''JEFF'' is throwing ORA-19206.
I tried -
WHERE name = CHR(39)||JEFF||CHR(39) but still getting ORA-19206.
What is best way to create a condition in where clause having string?
Thanks in advance,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

It appears you are missing a couple single quotes. You could use the overloaded function of DBMS_XMLGEN.NEWCONTEXT which takes in a SYS_REFCURSOR. This will make the number of single quotes less confusing (no need to keep escaping them). Try the below:
DECLARE
  get_data SYS_REFCURSOR;
  v_ctx dbms_xmlgen.ctxHandle;
BEGIN
  OPEN get_data FOR SELECT * FROM employees WHERE NAME = 'JEFF';
  v_ctx := dbms_xmlgen.newContext(get_data);
END;

Similar Messages

  • Dbms_xmlgen.newcontext query from multiple tables and ||

    I have two questions
    How do I get a dbms_xmlgen.context to query from multiple tables? I have been able to make it work with using one table only, but not with multiple tables.
    And how to get the || (concat) to work within my query for my output to an xml file?
    Here is my current query:
    create or replace function get_xml return clob is
    result clob;
    qryctx dbms_xmlgen.ctxHandle;
    SELECT DBMS_XMLGEN.getxml('select prefix, suffix, fiscal_yr
    FROM rcv.recv_accessions ra
    where ra.prefix = 8 and ra.fiscal_yr = 11')xml into result FROM dual;
    result := DBMS_XMLGEN.getXML(qryCtx);
    This is what I desire:
    SELECT DBMS_XMLGEN.getxml('select ra.prefix||'-'|| ra.suffix||'-'|| ra.fiscal_yr accession, ss.date_in, st.test
    FROM rcv.recv_accessions ra, ser.sero_samples ss, ser.sero_tests st
    where ra.prefix = 8 and ra.fiscal_yr = 11 and ss.raid = ra.id and st.ssid = ss.id')xml into result FROM dual;
    On this both the reference to multiple tables and the concat function cause errors.
    Thank you
    Edited by: user583094 on Mar 2, 2011 3:36 PM

    Hi,
    for the concat do I use xmlconcat?No, XMLConcat is used to concatenate XMLType fragments.
    The || operator will do fine, but you must escape any single quote inside the string :
    SELECT DBMS_XMLGEN.getxml(
    'SELECT ra.prefix ||''-''|| ra.suffix ||''-''|| ra.fiscal_yr as accession,
            ss.date_in,
            st.test
    FROM rcv.recv_accessions ra,
          ser.sero_samples ss,
          ser.sero_tests st
    WHERE ra.prefix = 8
    AND ra.fiscal_yr = 11
    AND ss.raid = ra.id
    AND st.ssid = ss.id'
    INTO result
    FROM dual;Or, use the quoting operator to define a custom string delimiter :
    SELECT DBMS_XMLGEN.getxml(
    q'{SELECT ra.prefix ||'-'|| ra.suffix ||'-'|| ra.fiscal_yr as accession,
            ss.date_in,
            st.test
    FROM rcv.recv_accessions ra,
          ser.sero_samples ss,
          ser.sero_tests st
    WHERE ra.prefix = 8
    AND ra.fiscal_yr = 11
    AND ss.raid = ra.id
    AND st.ssid = ss.id
    INTO result
    FROM dual;BTW, a good practice would be to use bind variables for the query. DBMS_XMLGEN can handle them nicely :
    CREATE OR REPLACE FUNCTION get_xml
    RETURN CLOB
    IS
    qryctx   DBMS_XMLGEN.ctxHandle;
    v_out    CLOB;
    qrystr   VARCHAR2(4000) :=
    'SELECT ra.prefix ||''-''|| ra.suffix ||''-''|| ra.fiscal_yr as accession,
            ss.date_in,
            st.test
    FROM rcv.recv_accessions ra,
          ser.sero_samples ss,
          ser.sero_tests st
    WHERE ra.prefix = :b_prefix
    AND ra.fiscal_yr = :b_fiscal_yr
    AND ss.raid = ra.id
    AND st.ssid = ss.id';
    BEGIN
    qryctx := DBMS_XMLGEN.newContext(qrystr);
    DBMS_XMLGEN.setBindValue(qryctx, 'b_prefix', '8');
    DBMS_XMLGEN.setBindValue(qryctx, 'b_fiscal_yr', '11');
    -- to generate empty elements if necessary :
    DBMS_XMLGEN.setNullHandling(qryctx, DBMS_XMLGEN.EMPTY_TAG);
    v_out := DBMS_XMLGEN.getXML(qryctx);
    DBMS_XMLGEN.closeContext(qryctx);
    RETURN v_out;
    END;

  • Cursor inside DBMS_XMLGen.newContext SetRowTag?

    Hi,
    I have the following code
    v_ctx := DBMS_XMLGen.newContext('select ' || chr(39) || 'F5' || chr(39) || ' as "sender",
                                            payloadid as "messageId",
                                            ordernumber as "orderNumber",
                                            recordtype as "recordType",
                                            billtoid as "billToId",
                                            shiptoid as "shipToId",
                                            shipperid as "shipperId",
                                            shipfromid as "shipFromId",
                                            currency as "currency",
                                            siteid as "siteId",
                                            carrierid as "carrierId",
                                            forwarderid as "forwarderId",
                                            flexcharacterattr7 as "flexCharacterAttr7",
                             hazardousindicator as "hazardousIndicator",
                                            motcode as "motCode",
                                            enduserid as "endUserId",
                                            orderdate as "orderDate",
                                            paymentterm as "paymentTerm",
                                            routedexportindicator as "routedExportIndicator",
                                            cursor(select linenumber as "lineNumber"
                                                     from f5_ec_order_ln_out b
                                                    where b.ordernumber = a.ordernumber) "lineRequest" 
                                       from f5_ec_order_hdr_out a
                                      where payloadid = 15');
    DBMS_XMLGen.setRowsetTag(v_ctx, 'orderRequest');
    DBMS_XMLGen.setRowTag(v_ctx, 'headerRequest');This is returning rows with a Row tag
    <lineRequest>
    <lineRequest_ROW>
    <lineNumber>1078</lineNumber>
    </lineRequest_ROW>
    <lineRequest_ROW>
    <lineNumber>1079</lineNumber>Is there any sort of command like
    DBMS_XMLGen.setRowTag(v_ctx, 'headerRequest');
    for a cursor inside this statement are there any like routines like
    DBMS_XMLGen.setRowsetTag(v_ctx, 'orderRequest');
    DBMS_XMLGen.setRowTag(v_ctx, 'headerRequest');
    for the cursor part inside or do I need to simply use a replace on my XML after?
    Thanks in advance!

    You can use xmlagg instead of the inner cursor:
    SQL> declare
      2   v_ctx dbms_xmlgen.ctxHandle;
      3   x varchar2(2000);
      4  begin
      5    v_ctx := DBMS_XMLGen.newContext('select dname ,
      6                                            (select xmlagg(xmlelement("lineNumber",ename))
      7                                                   from emp b
      8                                                  where b.deptno = a.deptno) "lineRequest"
      9                                     from dept a');
    10  
    11    DBMS_XMLGen.setRowsetTag(v_ctx, 'orderRequest');
    12    DBMS_XMLGen.setRowTag(v_ctx, 'headerRequest');
    13    x := dbms_xmlgen.getxml(v_ctx);
    14    dbms_output.put_line(x);
    15  end;
    16  /
    <?xml version="1.0"?>
    <orderRequest>
    <headerRequest>
    <DNAME>ACCOUNTING</DNAME>
      <lineRequest>
    <lineNumber>CLARK</lineNumber><lineNumber>KING</lineNumber><lineNumber>MILLER</lineNumber>  </lineRequest>
    </headerRequest>
    <headerRequest>
    <DNAME>RESEARCH</DNAME>
      <lineRequest>
    <lineNumber>SMITH</lineNumber><lineNumber>JONES</lineNumber><lineNumber>SCOTT</lineNumber><lineNumber>ADAMS</lineNumber><lineNumber>FORD</lineNumber>
    </lineRequest>
    </headerRequest>
    <headerRequest>
      <DNAME>SALES</DNAME>
    <lineRequest>
    <lineNumber>ALLEN</lineNumber><lineNumber>WARD</lineNumber><lineNumber>MARTIN</lineNumber><lineNumber>BLAKE</lineNumber><lineNumber>TURNER</lineNumber><lineNumber>JAMES</lineNumber>  </lineRequest>
    </headerRequest>
    <headerRequest>
    <DNAME>OPERATIONS</DNAME>
    </headerRequest>
    </orderRequest>
    PL/SQL procedure successfully completed.Max
    http://oracleitalia.wordpress.com

  • Dbms_xmlgen.newContext Perfomance

    Hi All,
    I am using dbms_xmlgen.newContext to generate XML , performance is fine when there are less records bur it reduces down when number of records increase, any ideas to optimise? I am using Cursor with in to break down in to tags

    [url http://forums.oracle.com/forums/thread.jspa?threadID=501834&tstart=0]When your query takes too long

  • XML publisher report using dbms_xmlgen (ORA-06502)

    Dear All,
    I have written the below code to generate xml output in Oracle Apps. The code is working fine for less records. But when CLOB size is more than 32k, then
    it giving the ORA-06502 error as fnd_file.put_line(fnd_file.output,v_result) can only write 32k at a time.
    Can anyone let me know how to handle this? Any help on this would be highly appreciated.
    PROCEDURE MAIN ( errbuf OUT VARCHAR2
    ,retcode OUT NUMBER
    ) IS
    TYPE g_query_ref IS REF CURSOR;
    v_query_ref g_query_ref;
    v_handle dbms_xmlgen.ctxhandle;
    v_result clob;
    BEGIN
    OPEN v_query_ref FOR
    SELECT invoice_num,
    description,
    customer_no,
    customer_name
    FROM XX_INVOICE_DETAILS;
    v_handle := dbms_xmlgen.newContext(v_query_ref);
    DBMS_XMLGEN.SETROWTAG (v_handle , 'INVOICE');
    v_result := dbms_xmlgen.getXML(v_handle);
    fnd_file.put_line(fnd_file.output,v_result);
    EXCEPTION
    when others then
    errbuf := sqlerrm;
    retcode := sqlcode;
    fnd_file.put_line(fnd_file.log,’sqlerrm ‘||sqlerrm);
    END MAIN;
    Thanks in Advance.
    Regards,
    Astik

    What you need to do is to chop your CLOB up into smaller strings, something like:
    l_size := DBMS_LOB.getlength (l_clob);
    IF (NVL (l_size, 0) = 0) THEN
    raise_application_error (-20001, 'CLOB is NULL');
    END IF;
    l_offset := 1;
    -- Loop
    WHILE (l_offset <= l_size) LOOP
    l_char := DBMS_LOB.SUBSTR (l_clob,1,l_offset);
    IF (l_char = CHR (10)) THEN
    FND_FILE.NEW_LINE(FND_FILE.output, 1);
    ELSE
    FND_FILE.PUT(FND_FILE.output, l_char);
    END IF;
    -- Increment Offset.
    l_offset:= l_offset+1;
    END LOOP;
    FND_FILE.NEW_LINE(fnd_file.output, 1);

  • DBMS_XMLGEN context not closing

    Hi,
    We have written a custom code,using DBMS_XMLGEN issue is in case of any exception the context is not getting closed.
    Because of which we are hitting ORA-01000: maximum open cursors exceeded.
    Below is the Psudeo code:
    BEGIN
    l_ctx := dbms_xmlgen.newcontext (p_sql);
    dbms_xmlgen.closecontext (l_ctx);
    dbms_xmlgen.getxml (l_ctx,l_clob);
    EXCEPTION
    WHEN OTHERS
    THEN
    dbms_xmlgen.closecontext (l_ctx);
    END;
    Any pointers will be appreciated.
    Thanks
    Shefali

    Below is the Psudeo code:
    Pseudo-code will not help us giving you a relevant answer.
    Please post a complete test case to reproduce the issue.
    Give your database version as well (SELECT * FROM v$version).
    Thanks.

  • How to change the default element tag using dbms_xmlgen

    here is my code that generate output for purchase order data. I followed the syntax shown in xml db developer guide.
    I am getting the results but element tags are CAPS letters( As the coloumn names in the type defenitions are stored in CAPS in Oracle). but I need to show in small letters as per my requirement.
    can anyone help me how to change the default tag names for elements.
    ==================================HERE IS THE CODE==================
    DECLARE
    qryCtx DBMS_XMLGEN.ctxHandle;
    result CLOB;
    BEGIN
    qryCtx := DBMS_XMLGEN.newContext
    ('SELECT PODL_H_T
    ( CLOSEDDATETIME ,
    COMPANY ,
    CAST(MULTISET
    (SELECT LINENUMBER ,
    COMPANY ,
    PURCHASEORDERID ,
    ITEM ,
    QUANTITYUM ,
    TOTALQUANTITY
    FROM cpo_wms_podl_LINES
    WHERE PURCHASEORDERID = PH.PURCHASEORDERID) as PurchaseOrderDetailList
    FROM cpo_wms_podl_HEADERS PH ');
    -- now get the result
    DBMS_XMLGEN.setRowSetTag(qryCtx, 'Receipts' );
    DBMS_XMLGEN.setRowTag(qryCtx, 'PurchaseOrder' );
    result := DBMS_XMLGEN.getXML(qryCtx);
    INSERT INTO temp_clob_tab VALUES (result);
    DBMS_XMLGEN.closeContext(qryCtx);
    END;
    -- select * from temp_clob_tab
    ===========create type script=====================
    cpo_wms_podl_HEADERS
    CREATE or replace TYPE PurchaseOrderDetail AS OBJECT(
    LINENUMBER VARCHAR2(400 BYTE),
    COMPANY VARCHAR2(400 BYTE),
    PURCHASEORDERID VARCHAR2(400 BYTE),
    ITEM VARCHAR2(400 BYTE),
    QUANTITYUM VARCHAR2(400 BYTE),
    TOTALQUANTITY NUMBER
    create type PurchaseOrderDetailList as table of PurchaseOrderDetail
    create table temp_clob_tab(result CLOB)
    create type podl_HEADERS_list_t as table of podl_HEADERS_t
    CREATE or replace TYPE PODL_H_T AS OBJECT
    CLOSEDDATETIME DATE,
    COMPANY VARCHAR2(400 BYTE),
    CREATEDDATETIME DATE,
    PURCHASEORDERID VARCHAR2(400 BYTE),
    SHIP_TO VARCHAR2(400 BYTE),
    linelist PurchaseOrderDetailList
    )

    but I need to show in small letters as per my requirement.add alias column names in double quotes as in
    SQL> select dbms_xmlgen.getxmltype('select dname "DeptName", loc "Location" from dept') dept_xml from dual
    DEPT_XML                                                                       
    <ROWSET>                                                                       
      <ROW>                                                                        
        <DeptName>ACCOUNTING</DeptName>                                            
        <Location>NEW YORK</Location>                                              
      </ROW>                                                                       
      <ROW>                                                                        
        <DeptName>RESEARCH</DeptName>                                              
        <Location>DALLAS</Location>                                                
      </ROW>                                                                       
      <ROW>                                                                        
        <DeptName>SALES</DeptName>                                                 
        <Location>CHICAGO</Location>                                               
      </ROW>                                                                       
      <ROW>                                                                        
        <DeptName>OPERATIONS</DeptName>                                            
        <Location>BOSTON</Location>                                                
      </ROW>                                                                       
      <ROW>                                                                        
        <DeptName>SALES</DeptName>                                                 
        <Location>MUNICH</Location>                                                
      </ROW>                                                                       
    </ROWSET>                                                                      
    1 row selected.

  • DBMS_XMLGEN, Carriage Returns XSLT to HTML

    Hi,
    I am facing an issue using the DBMS_XMLGEN. I have written a function (see under) that receive A SYS_REFCURSOR and return as a CLOB the XML with eventually transformed using a CLOB containing the passed XSLT code.
    The goal is to reuse several time this functions being called by other function/procedure (see under a sample of one of my procedure) of my package. Those procure/function being called by the front-end (Cold fusion) to retrieve and output the results. My purpose is to make independent of the front end solution the output generation. Any language that can call an Oracle Procedure/Function would be able to process the result with or without a XSLT.
    The issue is the CRLF (chr(10)+chr(13) seems to be lost in the process of the varchar2/clob data type used to generate the XML.
    A solution, is to modify the select statement and adding when necessary select ... replace(thefield,chr(10),'<br/>') thefield ... but this would request a post processing which I am trying to avoid.
    FUNCTION GEN_SYSTEM_GENEXML(
        INQUERYSTRING IN SYS_REFCURSOR,
        inStartRow    IN NUMBER,
        inMaxRows     IN NUMBER,
        inXsltString  IN CLOB)
      RETURN CLOB
    AS
      LHTMLOUTPUT XMLTYPE;
      xmlResult CLOB;
      CTX DBMS_XMLGEN.CTXHANDLE;
      lXMLData XMLType;
    BEGIN
      CTX := DBMS_XMLGEN.NEWCONTEXT(INQUERYSTRING);
      dbms_xmlgen.setNullHandling(ctx, 2);
      dbms_xmlgen.setIndentationWidth(ctx, 0);
      dbms_xmlgen.setRowSetTag(ctx, 'ROOT');
      dbms_xmlgen.setRowTag(ctx, 'item');
      dbms_xmlgen.setskiprows(ctx,inStartRow);
      DBMS_XMLGEN.SETMAXROWS(CTX,INMAXROWS);
      IF LENGTH(INXSLTSTRING) <> 0 AND INXSLTSTRING <>'[none]' THEN
        LXMLDATA              := DBMS_XMLGEN.GETXMLTYPE(CTX,DBMS_XMLGEN.NONE);
        LHTMLOUTPUT           :=LXMLDATA.TRANSFORM(XMLTYPE(INXSLTSTRING));
      ELSE
        xmlResult := dbms_xmlgen.getxml(ctx);
      END IF;
      DBMS_XMLGEN.CLOSECONTEXT(CTX);
      IF LENGTH(INXSLTSTRING) <> 0 AND INXSLTSTRING <>'[none]' THEN
        RETURN LHTMLOUTPUT.GETCLOBVAL();
      ELSE
        RETURN XMLRESULT;
      END IF;
    END gen_system_genexml;
    PROCEDURE PRC_GET_CF_CNS(
        inadonis IN NUMBER,
        inyear   IN NUMBER,
        INXSLT   IN CLOB,
        OUTRETURNED OUT CLOB)
    IS
      C1 SYS_REFCURSOR;
    BEGIN
      CASE INYEAR
      WHEN 2008 THEN
        OPEN C1 FOR SELECT ADONIS,
        CRIT_AA_MARKS,
        CRIT_AA_COMMENTS
      END CASE;
      OUTRETURNED :=GEN_SYSTEM_GENEXML(C1,0,10000,INXSLT);
    END PRC_GET_CF_CNS;

    (I mix my accounts, I posted with an outdated email)
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    PL/SQL Release 10.2.0.1.0 - Production
    "CORE     10.2.0.1.0     Production"
    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - ProductionIf I run without XLST I get (DBMSOUTPUT in SQLDevelopper) the CR/LF
    DECLARE
      INADONIS NUMBER;
      INYEAR NUMBER;
      INXSLT CLOB;
      OUTRETURNED CLOB;
    BEGIN
      INADONIS := 100858;
      INYEAR := 2010;
      INXSLT := '[none]';
      PKG_GENERAL.PRC_GET_CF_CNS(
        INADONIS => INADONIS,
        INYEAR => INYEAR,
        INXSLT => INXSLT,
        OUTRETURNED => OUTRETURNED
      DBMS_OUTPUT.PUT_LINE('OUTRETURNED = ' || OUTRETURNED);
    END;if I replace the '[none]' by the xslt string it looks, still in the dbms_output, being there...
    if I
    DBMS_OUTPUT.PUT_LINE('OUTRETURNED = ' || replace(OUTRETURNED,chr(10),'<br/>'));the result is broken...
    For the moment, I do this to avoid post-processing Cold Fusion
    FUNCTION GEN_SYSTEM_GENEXML(
        INQUERYSTRING IN SYS_REFCURSOR,
        inStartRow    IN NUMBER,
        inMaxRows     IN NUMBER,
        inXsltString  IN CLOB)
      RETURN CLOB
    AS
      LHTMLOUTPUT XMLTYPE;
      xmlResult CLOB;
      CTX DBMS_XMLGEN.CTXHANDLE;
      lXMLData XMLType;
    BEGIN
      CTX := DBMS_XMLGEN.NEWCONTEXT(INQUERYSTRING);
      dbms_xmlgen.setNullHandling(ctx, 2);
      dbms_xmlgen.setIndentationWidth(ctx, 0);
      dbms_xmlgen.setRowSetTag(ctx, 'ROOT');
      dbms_xmlgen.setRowTag(ctx, 'item');
      dbms_xmlgen.setskiprows(ctx,inStartRow);
      DBMS_XMLGEN.SETMAXROWS(CTX,INMAXROWS);
      dbms_xmlgen.setConvertSpecialChars(ctx, TRUE);
      IF LENGTH(INXSLTSTRING) <> 0 AND INXSLTSTRING <>'[none]' THEN
        LXMLDATA              := DBMS_XMLGEN.GETXMLTYPE(CTX,DBMS_XMLGEN.NONE);
        LHTMLOUTPUT           :=LXMLDATA.TRANSFORM(XMLTYPE(INXSLTSTRING));
      ELSE
        xmlResult := dbms_xmlgen.getxml(ctx);
      END IF;
      DBMS_XMLGEN.CLOSECONTEXT(CTX);
      IF LENGTH(INXSLTSTRING) <> 0 AND INXSLTSTRING <>'[none]' THEN
        RETURN replace(LHTMLOUTPUT.GETCLOBVAL(),'& l t ; br/ & g t ;','<br/>');
      ELSE
        RETURN XMLRESULT;
      END IF;
    END gen_system_genexml;& l t ; br/ & g t ; without the extract spaces
    Edited by: user4882594 on Jan 20, 2011 7:06 AM
    Edited by: user4882594 on Jan 20, 2011 7:06 AM

  • How to get UTF-8 encoding when create XML using DBMS_XMLGEN and UTL_FILE ?

    How to get UTF-8 encoding when create XML using DBMS_XMLGEN and UTL_FILE ?
    Hi,
    I do generate XML-Files by using DBMS_XMLGEN with output by UTL_FILE
    but it seems, the xml-Datafile I get on end is not really UTF-8 encoding
    ( f.ex. cannot verifying it correct in xmlspy )
    my dbms is
    NLS_CHARACTERSET          = WE8MSWIN1252
    NLS_NCHAR_CHARACTERSET     = AL16UTF16
    NLS_RDBMS_VERSION     = 10.2.0.1.0
    I do generate it in this matter :
    declare
    xmldoc CLOB;
    ctx number ;
    utl_file.file_type;
    begin
    -- generate fom xml-view :
    ctx := DBMS_XMLGEN.newContext('select xml from xml_View');
    DBMS_XMLGEN.setRowSetTag(ctx, null);
    DBMS_XMLGEN.setRowTag(ctx, null );
    DBMS_XMLGEN.SETCONVERTSPECIALCHARS(ctx,TRUE);
    -- create xml-file:
    xmldoc := DBMS_XMLGEN.getXML(ctx);
    -- put data to host-file:
    vblob_len := DBMS_LOB.getlength(xmldoc);
    DBMS_LOB.READ (xmldoc, vblob_len, 1, vBuffer);
    bHandle := utl_file.fopen(vPATH,vFileName,'W',32767);
    UTL_FILE.put_line(bHandle, vbuffer, FALSE);
    UTL_FILE.fclose(bHandle);
    end ;
    maybe while work UTL_FILE there is a change the encoding ?
    How can this solved ?
    Thank you
    Norbert
    Edited by: astramare on Feb 11, 2009 12:39 PM with database charsets

    Marco,
    I tryed to work with dbms_xslprocessor.clob2file,
    that works good,
    but what is in this matter with encoding UTF-8 ?
    in my understandig, the xmltyp created should be UTF8 (16),
    but when open the xml-file in xmlSpy as UTF-8,
    it is not well ( german caracter like Ä, Ö .. ):
    my dbms is
    NLS_CHARACTERSET = WE8MSWIN1252
    NLS_NCHAR_CHARACTERSET = AL16UTF16
    NLS_RDBMS_VERSION = 10.2.0.1.0
    -- test:
    create table nh_test ( s0 number, s1 varchar2(20) ) ;
    insert into nh_test (select 1,'hallo' from dual );
    insert into nh_test (select 2,'straße' from dual );
    insert into nh_test (select 3,'mäckie' from dual );
    insert into nh_test (select 4,'euro_€' from dual );
    commit;
    select * from nh_test ;
    S0     S1
    1     hallo
    1     hallo
    2     straße
    3     mäckie
    4     euro_€
    declare
    rc sys_refcursor;
    begin
    open rc FOR SELECT * FROM ( SELECT s0,s1 from nh_test );
    dbms_xslprocessor.clob2file( xmltype( rc ).getclobval( ) , 'XML_EXPORT_DIR','my_xml_file.xml');
    end;
    ( its the same when using output with DBMS_XMLDOM.WRITETOFILE )
    open in xmlSpy is:
    <?xml version="1.0"?>
    <ROWSET>
    <ROW>
    <S0>1</S0>
    <S1>hallo</S1>
    </ROW>
    <ROW>
    <S0>2</S0>
    <S1>straޥ</S1>
    </ROW>
    <ROW>
    <S0>3</S0>
    <S1>m㢫ie</S1>
    </ROW>
    <ROW>
    <S0>4</S0>
    <S1>euro_€</S1>
    </ROW>
    </ROWSET>
    regards
    Norbert

  • XML File Generation Issues using DBMS_XMLGEN

    Hi,
    I am using DBMS_XMLGEN package in a stored procedure to generate an XML file on Oracle 10 G R2 .But, the problem is the format in which the file is generated.
    CREATE OR REPLACE TYPE "state_info" as object (
    "@product_type" Number
    CREATE OR REPLACE TYPE prod_tab as TABLE OF "state_info";
    CREATE OR REPLACE TYPE state_t as object (
    "state_code" CHAR(2),
    "state_info" prod_tab
    CREATE OR REPLACE PROCEDURE get_xml_serviced_state (p_clob OUT clob)
    IS
    v_xmlctx DBMS_XMLGEN.ctxhandle;
    v_str VARCHAR2 (1000);
    BEGIN
    v_str := 'SELECT state_t(a.st_cd,CAST(MULTISET(select veh_type_id from svcd_st where st_cd =a.st_cd)as prod_tab)) as "state_info"
    from svcd_st a where a.st_cd in (select distinct st_cd from svcd_st) group by a.st_cd having count(*)>=1';
    v_xmlctx := DBMS_XMLGEN.newcontext (v_str);
    DBMS_XMLGEN.setrowsettag (v_xmlctx,'serviced_state');
    DBMS_XMLGEN.setrowtag (v_xmlctx,NULL);
    p_clob := DBMS_XMLGEN.getxml (v_xmlctx);
    printclobout(p_clob);
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    NULL;
    WHEN OTHERS
    THEN
    RAISE;
    END;
    SHOW ERRORS
    Output :
    <serviced_state>
    <state_info state_code="VA">
    <state_info>
    <state_info product_type="2"/>
    <state_info product_type="5"/>
    <state_info product_type="9"/>
    </state_info>
    </state_info>
    <state_info state_code="AB">
    <state_info>
    <state_info product_type="2"/>
    <state_info product_type="5"/>
    <state_info product_type="9"/>
    </state_info>
    </state_info>
    </serviced_state>
    Required it in below format:
    <serviced_state>
    <state_info state_code="VA">
    <state_info product_type="2"/>
    <state_info product_type="5"/>
    <state_info product_type="9"/>
    </state_info>
    <state_info state_code="AB">
    <state_info product_type="2"/>
    <state_info product_type="5"/>
    <state_info product_type="9"/>
    </state_info>
    </serviced_state>
    I just need to put in all the rows under one single tag.Appreciate your early responses.
    Thanks.

    Your wanted XML output is NOT VALID...(try it yourself on http://tools.decisionsoft.com/schemaValidate/)

  • DBMS_XMLGEN not working for me

    I'm just starting with this, so I may be missing something.
    I have 9.2.0.1.0 installed on Linux Redhat.
    I'm trying to create an XML document by querying a table
    as described in the Oracle 9i XML Database Developer's Guide, pg 10-28.
    I'm querying a very simple table, and it seems to start, but then it creates locks and that is it. I don't get errors, it just doesn't work. Below is what I do/get:
    create table xml_test_clob (result clob);
    declare
    v_result clob;
    l_ctx dbms_xmlgen.ctxHandle;
    l_sql varchar2(400);
    begin
    l_sql := 'select * from scott.emp';
    l_ctx := dbms_xmlgen.newContext(l_sql);
    v_result := dbms_xmlgen.getXml(l_ctx);
    insert into xml_test_clob VALUES(v_result);
    dbms_output.put_line('testing');
    dbms_xmlgen.closecontext(l_ctx);
    exception
    when others then
    dbms_output.put_line('error: '||to_char(sqlcode));
    end;
    testing
    PL/SQL procedure successfully completed.
    SQL> select * from xml_test_clob;
    RESULT
    <?xml version="1.0"?>
    <ROWSET>
    <ROW>
    <EMPNO>7369</EMPNO>
    <ENAME>SMITH</ENAM
    SQL>
    It seems like it just stops, and then I have locks which I have to clear in order to truncate the table to try again.
    I'm just in a 'normal' schema. Do I have to do something else to make this work?
    Thanks,
    Tim

    Mark,
    Yes I did run catpatch.sql.
    when trying to compile dbms_xmlgen, I get:
    SQL> alter package dbms_xmlgen compile body;
    alter package dbms_xmlgen compile body
    ERROR at line 1:
    ORA-00604: error occurred at recursive SQL level 1
    ORA-04045: errors during recompilation/revalidation of LBACSYS.LBAC_EVENTS
    ORA-06508: PL/SQL: could not find program unit being called
    ORA-06512: at line 2
    ORA-06508: PL/SQL: could not find program unit being called
    ORA-06512: at line 2
    SQL>
    I did a search on metalink and found that LBACSYS is
    'Label Security'. I don't recall selecting this to be
    installed when I first installed the db.
    I found a post on metalink that showed a script, catnools.sql that removes Label Security. Do you think
    I should run it?
    Is there some way to regenerate dbms_xmlgen (rather than
    recompile?)

  • Using dbms_xmlgen with a CAST statement

    The following code populates a plsql collection and then attempts to select from it using dbms_xmlgen.
    the following error results --
    DECLARE
    ERROR at line 1:
    ORA-19206: Invalid value for query or REF CURSOR parameter
    ORA-06512: at "SYS.DBMS_XMLGEN", line 83
    ORA-06512: at line 56
    The query is correct as the commented out select at end of block works fine.
    Can dbms_xmlgen be used in such a way and if not is there a workaround.
    Thanks
    DECLARE
    types declared on the database
    create or replace type bus_tab_obj AS object
    ( BUSINESS_MODEL_ID NUMBER(10)
    ,BUSINESS_MODEL_VER_NO NUMBER(5)
    ,BUSINESS_MODEL_NAME VARCHAR2(30));
    create or replace TYPE bus_table AS TABLE of bus_tab_obj;
    package level variable bus_table_recs in package get_values_pkg
    myxml sys.xmltype;
    queryCtx DBMS_XMLGen.ctxhandle;
    BEGIN
    -- initialise and delete
    get_values_pkg.bus_table_recs := bus_table(NULL,NULL,NULL);
    get_values_pkg.bus_table_recs.DELETE;
    -- select some records to put in the collection
    for x in ( select BUSINESS_MODEL_ID
    ,BUSINESS_MODEL_VER_NO
    ,BUSINESS_MODEL_NAME
    from BRK_BUSINESS_MODEL )
    LOOP
    get_values_pkg.bus_table_recs.extend;
    get_values_pkg.bus_table_recs := bus_table(bus_tab_obj(x.business_model_id
    ,x.business_model_ver_no
    ,x.business_model_name));
    END LOOP;
    -- retrieve the records from the collection as xml
    queryCtx := DBMS_XMLGen.newContext('select a.business_model_name data from THE ( select cast( get_values_pkg.bus_table_recs as bus_table ) from dual ) a order by data');
    dbms_xmlgen.setMaxRows(queryCtx,1);
    myxml := DBMS_XMLGen.getXMLType(queryCtx);
    dbms_output.put_line(myxml.extract('/*').getStringVal());
    this works!
    for x in ( select a.business_model_name data
    from THE ( select cast( get_values_pkg.bus_table_recs as bus_table ) from dual ) a
    order by data )
    loop
    dbms_output.put_line( x.data );
    end loop;
    END;
    /

    891794 wrote:
    Thank you all , see I am new to this database field , I am not a pro.Not a problem. However, one of the very first things you should learn is that dynamic SQL is seldom needed and invariably just plain wrong.
    If a table name is dynamic, or a column name is dynamic - then chances are excellent that your data model is already fubar'ed (or malema'ed to put it in a za.org perspective).
    And even when you are in the very exceptional situation where dynamic SQL is needed, SQL injection is a MAJOR security concern.. and almost always ignored by implementing shoddy code to create and execute the dynamic SQL.

  • DBMS_XMLGEN --Number of active cursors in increased in Exception block

    Hi ,
    We have a custom code that use DBMS_XMLGEN,the issue is when any exception happens the Number os active cusrors increse and when it happens in a lopp we hit 1000ORA-01000: maximum open cursors exceeded.
    Although I close the context in the exception Block.
    Below is sample code where I could replicate this:
    Step1.Create a table
    CREATE TABLE EMP(EMP_NO NUMBER,EMPNAME VARCHAR2(100));
    Step2:
    Create  a Procedure:
    CREATE OR REPLACE PROCEDURE TEST_XMLGEN
    AS
    l_clob CLOB;
      l_ctx         dbms_xmlgen.ctxhandle;
      p_sql VARCHAR2(4000):='SELECT EMP_NO,,EMPNAME FROM EMP';--syntax error on purpose ,so that exception happens
      l_cursor_count NUMBER;
    BEGIN
    SELECT VALUE
               INTO l_cursor_count
               FROM v$mystat a, v$statname b
              WHERE     a.statistic# = b.statistic#
                    AND b.name = 'opened cursors current';
            DBMS_OUTPUT.PUT_LINE ('open cursors place00' || l_cursor_count);
    l_ctx := dbms_xmlgen.newcontext (p_sql);
    SELECT VALUE
               INTO l_cursor_count
               FROM v$mystat a, v$statname b
              WHERE     a.statistic# = b.statistic#
                    AND b.name = 'opened cursors current';
             DBMS_OUTPUT.PUT_LINE('open cursors place01' || l_cursor_count);
    dbms_xmlgen.getxml (l_ctx,l_clob);
    SELECT VALUE
               INTO l_cursor_count
               FROM v$mystat a, v$statname b
              WHERE     a.statistic# = b.statistic#
                    AND b.name = 'opened cursors current';
             DBMS_OUTPUT.PUT_LINE ('open cursors place02' || l_cursor_count);
    DBMS_OUTPUT.PUT_LINE('l_clob:'||l_clob);
    dbms_xmlgen.closecontext (l_ctx);
    SELECT VALUE
               INTO l_cursor_count
               FROM v$mystat a, v$statname b
              WHERE     a.statistic# = b.statistic#
                    AND b.name = 'opened cursors current';
             DBMS_OUTPUT.PUT_LINE ('open cursors place03' || l_cursor_count);
    EXCEPTION
    WHEN OTHERS
    THEN
    SELECT VALUE
               INTO l_cursor_count
               FROM v$mystat a, v$statname b
              WHERE     a.statistic# = b.statistic#
                    AND b.name = 'opened cursors current';
             DBMS_OUTPUT.PUT_LINE ('open cursors place04' || l_cursor_count);
    dbms_xmlgen.closecontext (l_ctx);
    SELECT VALUE
               INTO l_cursor_count
               FROM v$mystat a, v$statname b
              WHERE     a.statistic# = b.statistic#
                    AND b.name = 'opened cursors current';
             DBMS_OUTPUT.PUT_LINE ('open cursors place05' || l_cursor_count);
    END;
    Step3: Execute above Procedure
    If you look at the number of active cursor it is increased in exception block,I suspect this is what is causing issue with my program too.Any suggestions to solve this issue.
    Thanks
    Shefali

    Did you mean this test:
    declare
      ts timestamp;
      type tp_strings is table of varchar2(32767) index by pls_integer;
      t_strings tp_strings;
      t_tmp xmltype;
      t_nd dbms_xmldom.domnode;
      t_nl dbms_xmldom.domnodelist;
      t_clob clob;
    begin
      t_clob := '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
             || '<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="5000" uniqueCount="5000">';
      for i in 1 .. 5000
      loop
        t_clob := t_clob || to_clob( '<si><t>A' || to_char( i ) || '</t></si>' );
      end loop;
      t_clob := t_clob || '</sst>';
      t_tmp := xmltype( t_clob );
      t_strings.delete;
      ts := systimestamp;
          select str
          bulk collect into t_strings
          from xmltable( xmlnamespaces( default 'http://schemas.openxmlformats.org/spreadsheetml/2006/main' )
                       , '/sst/si' passing t_tmp
                       columns str clob path 't'
      dbms_output.put_line( systimestamp - ts );
      dbms_output.put_line( t_strings.count() || ' ' || t_strings( t_strings.first )  || ' ' || t_strings( t_strings.last ) );
      t_strings.delete;
      ts := systimestamp;
          select /*+ NO_XML_QUERY_REWRITE */ str
          bulk collect into t_strings
          from xmltable( xmlnamespaces( default 'http://schemas.openxmlformats.org/spreadsheetml/2006/main' )
                       , '/sst/si' passing t_tmp
                       columns str clob path 't'
      dbms_output.put_line( systimestamp - ts );
      dbms_output.put_line( t_strings.count() || ' ' || t_strings( t_strings.first )  || ' ' || t_strings( t_strings.last ) );
      t_strings.delete;
      ts := systimestamp;
          t_nd := dbms_xmldom.makenode( dbms_xmldom.getdocumentelement( dbms_xmldom.newdomdocument( t_tmp ) ) );
          t_nl := dbms_xslprocessor.selectnodes( t_nd, '/sst/si/t/text()', 'xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"' );
          for i in 0 .. dbms_xmldom.getlength( t_nl ) - 1
          loop
            t_strings( i ) := dbms_xmldom.getnodevalue( dbms_xmldom.item( t_nl, i ) );
          end loop;
      dbms_output.put_line( systimestamp - ts );
      dbms_output.put_line( t_strings.count() || ' ' || t_strings( t_strings.first )  || ' ' || t_strings( t_strings.last ) );
    end;  

  • Dbms_xmlgen using pl-sql record type

    Hi
    I want to pass pl-sql record type and want to generate xml. Can dbms_xmlgen access pl-sql record type instead of query?
    OR please let me know any other package to pass pl-sql record type and generate XML.
    Thanks in advance

    Can dbms_xmlgen access pl-sql record type instead of query?Don't think so, but can't you pass the individual record components:
    SQL> declare
      type rec is record
        a   int,
        b   varchar2 (30)
      r     rec;
      ctx   int;
      x     xmltype;
    begin
      r.a := 1;
      r.b := 'Michael';
      ctx := dbms_xmlgen.newcontext ('select :x id, :y name from dual');
      dbms_xmlgen.setbindvalue (ctx, 'x', r.a);
      dbms_xmlgen.setbindvalue (ctx, 'y', r.b);
      x := dbms_xmlgen.getxmltype (ctx);
      dbms_output.put_line (x.getstringval ());
      dbms_xmlgen.closecontext (ctx);
    end;
    <ROWSET>
    <ROW>
      <ID>1</ID>
      <NAME>Michael</NAME>
    </ROW>
    </ROWSET>
    PL/SQL procedure successfully completed.?

  • Dbms_xmlgen: write emp content to xml file

    Hi.
    I have the following procedure to write the content of the emp table in xml to a file:
    CREATE OR REPLACE PROCEDURE BSP_DBMSXMLGEN IS
    v_ctx DBMS_XMLGen.ctxHandle;
    v_file Utl_File.File_Type;
    v_xml CLOB;
    v_more BOOLEAN := TRUE;
    l_exception varchar2(2000);
    BEGIN
    -- XML context erzeugen
    v_ctx := DBMS_XMLGen.newContext('SELECT * from emp_big');
    -- Root Element und Zeilentag setzen
    DBMS_XMLGen.setRowsetTag(v_ctx, 'Emp');
    DBMS_XMLGen.setRowTag(v_ctx, 'Zeile');
    -- XML Dokument erzeugen
    v_xml := DBMS_XMLGen.GetXML(v_ctx);
    DBMS_XMLGen.closeContext(v_ctx);
    -- Ausgabedatei erzeugen
    v_file := Utl_File.FOpen('XML_DIR', 'BSP_DBMSXMLGEN.xml', 'w');
    -- In Datei schreiben
    WHILE v_more LOOP
    Utl_File.Put(v_file, Substr(v_xml, 1, 32767));
    IF Length(v_xml) > 32767 THEN
    v_xml := Substr(v_xml, 32768);
    ELSE
    v_more := FALSE;
    END IF;
    END LOOP;
    Utl_File.FClose(v_file);
    EXCEPTION
    when OTHERS then
    l_exception := sqlerrm;
    dbms_output.put_line('Error: ' || l_exception);
    END;
    The procedure works well with 14 emp rows. But after duplicating the rows a few times the procedure stops working...
    insert into emp_big select * from emp_big;
    commit;
    select count(*) from emp_big;
    COUNT(*)
    960
    exec bsp_dbmsxmlgen;
    The file content:
    <?xml version="1.0"?>
    <Emp>
    <Zeile>
    <EMPNO>7369</EMPNO>
    <ENAME>SMITH</ENAME>
    <JOB>CLERK</JOB>
    <MGR>7902</MGR>
    <HIREDATE>17.12.80</HIREDATE>
    <SAL>800</SAL>
    <DEPTNO>20</DEPTNO>
    </Zeile>
    <Zeile>
    <EMPNO>7499</EMPNO>
    <E
    The procedure stops writing to file in the middle of a table row...
    Any ideas?
    Thanks
    Markus

    Thanks, Marco, but I think I need to be more clear. The original XML data in the XMLType field looks like:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <metadata>
    </metadata>where "metadata" is the root node of the entire file. What happens is when I run the script listed above, the name of the field being queried gets added as a root node, which I don't want. I did figure out how to omit the "ROW" and ROWSET" nodes from being placed in the resulting XML flat file. Using the same script, I replaced:
    -- Root Element und Zeilentag setzen
    DBMS_XMLGen.setRowsetTag( v_ctx, 'Emp' );
    DBMS_XMLGen.setRowTag( v_ctx, 'Zeile' );with
    -- Root Elements
    DBMS_XMLGen.setRowsetTag( v_ctx, '' );
    DBMS_XMLGen.setRowTag( v_ctx, '' );I simply removed "Emp" and "Zeile." By doing this, those nodes are omitted. I still can't figure out how to omit the "XML_DATA" node.

Maybe you are looking for

  • How do I get a Mini DisplayPort adapter and HDMI connection working for my Older MacBook Pro?

    I bought a Belkin Mini DisplayPort adapter and attempted to hook it up on two different tvs using two different HDMI cords. I've always received a "no signal" message. I haven't even been able to get my desktop to appear. My display settings doesn't

  • How to make a "SSWA JSP Function"  as query Only in Oracle 11i or R12

    Please someone help me in making a SSWA JSP Page as read only.. For "forms" we use a parameter QUERY_ONLY="YES",what is the procedure for making a JSP as read only?

  • Purchase Quotation

    Hello To All, I am working on SAP 8.81 PL00 system. i am working on Procurement Confirmation Wizard before it i have made sales order for FG001 and select Procureent document in sales order logistic tab.now this Material(FG001) also have bill of mate

  • Dunning selection parameters

    Dear Friends, I want to do dunning Portion wise, is there a way or event by which this can be achieved. In transactions FPVA or for instance any mass trasaction activities, the fields under custom selections doesn;t seems to be of any relevance. Only

  • Getting Error When Uploading Role

    Hi,    I downloaded the role from one system when iam uploading to another system iam getting error : The file does not contain any valid data. guide me for the same. Thanku