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

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;

  • 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

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

  • CURSOR Inside select statement

    Hi,
    I am trying to generate reports in XML Publisher using PL/SQL Procedure. Following is my procedure:
    PROCEDURE XXDL_PO_VEN_SUMMARY_BY_VEN (ERR_BUFF VARCHAR2,
                        RETCODE VARCHAR2,
                   in_vendor_number IN VARCHAR2,
                        in_start_date IN VARCHAR2,
                   in_end_date IN VARCHAR2
    IS
              SQL_STMT VARCHAR2(15000);
              result CLOB;
              in_vendor_summary_from_date DATE;
              in_vendor_summary_to_date DATE;
              CURSOR_WHERE_CLAUSE VARCHAR2(1000);
    BEGIN
              in_vendor_summary_from_date := TO_DATE(in_start_date,'YYYY/MM/DD HH24:MI:SS');
              in_vendor_summary_to_date := TO_DATE(in_end_date,'YYYY/MM/DD HH24:MI:SS');
              --DBMS_OUTPUT.PUT_LINe('start date object'||in_vendor_summary_from_date);
              --DBMS_OUTPUT.PUT_LINe('end date object'||in_vendor_summary_to_date);
    IF in_start_date IS NOT NULL AND LENGTH(in_start_date) > 0 AND in_end_date IS NOT NULL AND LENGTH(in_end_date) > 0 THEN
         CURSOR_WHERE_CLAUSE := 'AND TO_DATE(CONCAT(CONCAT(SUMMARY_MONTH, ''/''), SUMMARY_YEAR),''MM/YYYY'') BETWEEN'
         ||' '''||in_vendor_summary_from_date||''' AND '''||in_vendor_summary_to_date||'''';
    END IF;
    IF in_vendor_number IS NOT NULL AND LENGTH(in_vendor_number)>0 THEN
              CURSOR_WHERE_CLAUSE := CURSOR_WHERE_CLAUSE || ' AND UPPER(VENDOR_NUM) LIKE UPPER('''||in_vendor_number||'%'')';
    END IF;
    --DBMS_OUTPUT.PUT_LINe('cursor where clause : '||CURSOR_WHERE_CLAUSE );
    SQL_STMT := 'SELECT VS.VENDOR_NUM,' ||
              ' VS.VENDOR_NAME,' ||
              ' VS.SUMMARY_MONTH,' ||
              ' VS.SUMMARY_YEAR,' ||
              ' VS.ORD_TOTAL_CNT,' ||
              ' VS.ORD_DOLLAR_AMT,'||
              ' VS.RPO_TOTAL_CNT,' ||
              ' VS.RPO_DOLLAR_AMT,'||
              ' VS.CWA_TOTAL_CNT,' ||
              ' VS.CWA_DOLLAR_AMT,'||
              ' VS.STD_TOTAL_CNT,' ||
              ' VS.STD_DOLLAR_AMT,'||
              ' VS.BLM_TOTAL_CNT,' ||
              ' VS.BLM_DOLLAR_AMT,'||
              ' VS.INVOICE_TOTAL_CNT,' ||
              ' VS.INVOICE_DOLLAR_AMT, ' ||
              ' CURSOR (SELECT nvl(SUM( nvl(VS1.ORD_TOTAL_CNT,0)),0) FROM STANPRS.VENDOR_SUMMARY VS1 '||
              ' ) TOTAL_ORDERS, ' ||
              ' CURSOR(SELECT nvl(SUM(nvl(VS2.ORD_DOLLAR_AMT,0)),0) FROM STANPRS.VENDOR_SUMMARY VS2 '||
              ' ) TOTAL_DOLLARS,' ||
              ' CURSOR(SELECT nvl(SUM(nvl(VS3.RPO_TOTAL_CNT,0)),0) FROM STANPRS.VENDOR_SUMMARY VS3 '||
              ' ) RPO_ORDERS,' ||
              ' CURSOR(SELECT nvl(SUM(nvl(VS4.RPO_DOLLAR_AMT,0)),0) FROM STANPRS.VENDOR_SUMMARY VS4 '||
              ' ) RPO_DOLLARS,' ||
              ' CURSOR(SELECT nvl(SUM(nvl(VS5.CWA_TOTAL_CNT,0)),0) FROM STANPRS.VENDOR_SUMMARY VS5 '||
              ' ) CWA_ORDERS,' ||
              ' CURSOR(SELECT nvl(SUM(nvl(VS6.CWA_DOLLAR_AMT,0)),0) FROM STANPRS.VENDOR_SUMMARY VS6 '||
              ' ) CWA_DOLLARS,' ||
              ' CURSOR(SELECT nvl(SUM(nvl(VS7.STD_TOTAL_CNT,0)),0) FROM STANPRS.VENDOR_SUMMARY VS7 '||
              ' ) STD_ORDERS,' ||
              ' CURSOR(SELECT nvl(SUM(nvl(VS8.STD_DOLLAR_AMT,0)),0) FROM STANPRS.VENDOR_SUMMARY VS8 '||
              ' ) STD_DOLLARS,' ||
              ' CURSOR(SELECT nvl(SUM(nvl(VS9.BLM_TOTAL_CNT,0)),0) FROM STANPRS.VENDOR_SUMMARY VS9 '||
              ' ) BLM_ORDERS,' ||
              ' CURSOR(SELECT nvl(SUM(nvl(VS10.BLM_DOLLAR_AMT,0)),0) FROM STANPRS.VENDOR_SUMMARY VS10 '||
              ' ) BLM_DOLLARS,' ||
              ' CURSOR(SELECT nvl(SUM(nvl(VS11.INVOICE_TOTAL_CNT,0)),0) FROM STANPRS.VENDOR_SUMMARY VS11 '||
              ' ) TOTAL_INVOICES,' ||
              ' CURSOR(SELECT nvl(SUM(nvl(VS12.INVOICE_DOLLAR_AMT,0)),0) FROM STANPRS.VENDOR_SUMMARY VS12 '||
              ' ) INVOICE_DOLLARS, ' ||
    ' CURSOR(SELECT nvl(SUM(nvl(V1.RPO_TOTAL_CNT,0)),0)*100 / decode(SUM(nvl(V1.RPO_TOTAL_CNT,0)),0,1,NULL,1,SUM(nvl(V1.RPO_TOTAL_CNT,0))) FROM '|| ' STANPRS.VENDOR_SUMMARY V1 ) RPO_ORDERS_PER,' ||
    ' CURSOR(SELECT NVL(SUM(nvl(V2.RPO_DOLLAR_AMT,0)),0)*100 / decode(SUM(nvl(V2.RPO_DOLLAR_AMT,0)),0,1,NULL,1,SUM(nvl(V2.RPO_DOLLAR_AMT,0))) '|| 'FROM STANPRS.VENDOR_SUMMARY V2 ) RPO_DOLLARS_PER,' ||
    ' CURSOR(SELECT NVL(SUM(nvl(V3.CWA_TOTAL_CNT,0)),0)*100 / decode(SUM(nvl(V3.CWA_TOTAL_CNT,0)),0,1,NULL,1,SUM(nvl(V3.CWA_TOTAL_CNT,0))) FROM '|| 'STANPRS.VENDOR_SUMMARY V3 ) CWA_ORDERS_PER,' ||
    ' CURSOR(SELECT NVL(SUM(nvl(V4.CWA_DOLLAR_AMT,0)),0)*100 / decode(SUM(nvl(V4.CWA_DOLLAR_AMT,0)),0,1,NULL,1,SUM(nvl(V4.CWA_DOLLAR_AMT,0))) '||
    'FROM STANPRS.VENDOR_SUMMARY V4 ) CWA_DOLLARS_PER,' ||
    ' CURSOR(SELECT NVL(SUM(nvl(V5.STD_TOTAL_CNT,0)),0)*100 / decode(SUM(nvl(V5.STD_TOTAL_CNT,0)),0,1,NULL,1,SUM(nvl(V5.STD_TOTAL_CNT,0))) FROM '|| 'STANPRS.VENDOR_SUMMARY V5 ) STD_ORDERS_PER,' ||
    ' CURSOR(SELECT NVL(SUM(nvl(V6.STD_DOLLAR_AMT,0)),0)*100 / decode(SUM(nvl(V6.STD_DOLLAR_AMT,0)),0,1,NULL,1,SUM(nvl(V6.STD_DOLLAR_AMT,0))) '||
    'FROM STANPRS.VENDOR_SUMMARY V6 ) STD_DOLLARS_PER,' ||
    ' CURSOR(SELECT NVL(SUM(nvl(V7.BLM_TOTAL_CNT,0)),0)*100 / decode(SUM(nvl(V7.BLM_TOTAL_CNT,0)),0,1,NULL,1,SUM(nvl(V7.BLM_TOTAL_CNT,0))) '||
    'FROM STANPRS.VENDOR_SUMMARY V7 ) BLM_ORDERS_PER,' ||
    ' CURSOR(SELECT NVL(SUM(nvl(V8.BLM_DOLLAR_AMT,0)),0)*100 / decode(SUM(nvl(V8.BLM_DOLLAR_AMT,0)),0,1,NULL,1,SUM(nvl(V8.BLM_DOLLAR_AMT,0))) '||
    'FROM STANPRS.VENDOR_SUMMARY V8 ) BLM_DOLLARS_PER,' ||
    'CURSOR(SELECT NVL(SUM(nvl(V9.INVOICE_TOTAL_CNT,0)),0)*100 / '||
    'decode(SUM(nvl(V9.INVOICE_TOTAL_CNT,0)),0,1,NULL,1,SUM(nvl(V9.INVOICE_TOTAL_CNT,0))) FROM '||
    'STANPRS.VENDOR_SUMMARY V9 ) TOTAL_INVOICES_PER, ' ||
    'CURSOR(SELECT NVL(SUM(nvl(V10.INVOICE_DOLLAR_AMT,0)),0)*100/ decode(SUM(nvl(V10.INVOICE_DOLLAR_AMT,0)),0,1,NULL,1,SUM(nvl(V10.INVOICE_DOLLAR_AMT,0))) FROM STANPRS.VENDOR_SUMMARY V10 ) INVOICE_DOLLARS_PER' ||
    ' FROM STANPRS.VENDOR_SUMMARY VS' ||
    ' WHERE';
    --DBMS_OUTPUT.PUT_LINE('STANPRS.VENDOR_SUMMARY V10  WHERE V10.VENDOR_NUM = VS.VENDOR_NUM ') INVOICE_DOLLARS_PER');
    IF in_start_date IS NOT NULL AND LENGTH(in_start_date) > 0 AND in_end_date IS NOT NULL AND LENGTH(in_end_date) > 0 THEN
         SQL_STMT := SQL_STMT || ' TO_DATE(CONCAT(CONCAT(VS.SUMMARY_MONTH, ''/''), VS.SUMMARY_YEAR),''MM/YYYY'') BETWEEN '
         ||' '''||in_vendor_summary_from_date||''' AND '''||in_vendor_summary_to_date||'''';
    END IF;
    IF in_vendor_number IS NOT NULL AND LENGTH(in_vendor_number)>0 THEN
         IF SUBSTR(SQL_STMT, LENGTH(SQL_STMT)-4) = 'WHERE' THEN
              SQL_STMT := SQL_STMT || ' UPPER(VS.VENDOR_NUM) LIKE UPPER('''||in_vendor_number||'%'')';
         ELSE
              SQL_STMT := SQL_STMT || ' AND UPPER(VS.VENDOR_NUM) LIKE UPPER('''||in_vendor_number||'%'')';
         END IF;
    END IF;
    IF in_vendor_name IS NOT NULL AND LENGTH(in_vendor_name)>0 THEN
         IF SUBSTR(SQL_STMT, LENGTH(SQL_STMT)-4) = 'WHERE' THEN
              SQL_STMT := SQL_STMT || ' UPPER(VS.VENDOR_NAME) LIKE UPPER('''||in_vendor_name||'%'')';
         ELSE
              SQL_STMT := SQL_STMT || ' AND UPPER(VS.VENDOR_NAME) LIKE UPPER('''||in_vendor_name||'%'')';
         END IF;
    END IF;
    IF SUBSTR(SQL_STMT, LENGTH(SQL_STMT)-4) = 'WHERE' THEN
         SQL_STMT := SQL_STMT || ' VS.VENDOR_NUM = '''||in_vendor_number||'''';
    END IF; */
    SQL_STMT := SQL_STMT || ' ORDER BY VS.VENDOR_NUM, VS.VENDOR_NAME ASC';
    --insert into XX_ERROR VALUES('Spriha',SQL_STMT);
    SELECT DBMS_XMLGEN.GETXML(SQL_STMT) INTO result FROM DUAL;
    FND_FILE.PUT_LINE(FND_FILE.OUTPUT, result);
    EXCEPTION
         WHEN OTHERS THEN
              FND_FILE.PUT_LINE(FND_FILE.OUTPUT, SQLERRM);
    END XXDL_PO_VEN_SUMMARY_BY_VEN ;
    Now u can see in this Procedure that i have created so many cursors. i.e. for one function i have created one cursor. at present thesecursors are working fine. but the time i will put the where clause inside the cursors this will throw an ERROR ' ORA-01460 Unimplemented or Unreasonable Conversion Request'. Also these cursors are working with where clause but they are not working together. i.e when i will remove some cursors then i am not getting any error but at present i.e. without any where clause they all r working fine. Seriously i am not getting anything that what is happening. Can anyone help me? waiting for the reply....
    Thanks
    Spriha

    This is pretty much a poster for ugly code.
    Simplify this down to the bare minimum and debug it. Then add back the rest of the functionality.
    But I am at a loss, looking at this code, as to why any cursor is either desirable or required.

  • Using cursor inside other procedure

    Hello,
    I have a question, i have a procedure that have several IN parameters and one OUT sys_refcursor. i need to call this procedure from other procedure, and i need to use the values that cursor have it inside, for example, my cursor have 5 columns with several IDs and i need to use this ID and send it like XMLtype.
    Is it possible to use the value from cursor??
    Thank you.
    Samm.
    Edited by: Samm on Mar 10, 2009 2:37 PM

    several variables?? how?
    create or replace procedure test_out (pOutValue OUT sys_refcursor)
    is
    begin
       open pOutValue for select object_id,object_name,.... from all_objects where rownum < 10;
    end;
    declare
       l_Cursor     SYS_REFCURSOR;
       l_Object_id  number;
      l_object_name varchar2;
    begin
       test_out(l_Cursor);
       loop
       fetch l_Cursor into l_Object_id *???????????!!!!!!!!!!!, how to fetch the object_name also?*
       exit when l_Cursor%notfound;
       end loop;
    end;Edited by: Samm on Mar 10, 2009 4:04 PM

  • Change Mouse Cursor Inside JTextPane

    Hello Everyone,
    I am trying to change the mouse cursor of a specific text of a JTextPane to:
    setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));This specific text is a hyperlink which its color is blue and it is underlined, so I want to have the mouse cursor changed to make clearer that you can click on it.
    I thought about trying to track the mouse position inside the JTextPane until it reachs the text position but I am not aware of any class that provides this feature. Does anyone know or have another ideia?
    Any help is appreciated,
    Thanks in advance
    Edited by: ZeroTodd on Aug 10, 2010 6:26 AM

    This specific text is a hyperlink which its color is blue and it is underlined, so I want to have the mouse cursor changed to make clearer that you can click on it.That's the default behavior (in the default Metal LaF, at least) when you setEditable(false). And IMO it doesn't make much sense to change the cursor or allow hyperlink navigation when the text pane is editable.
    db

  • Calling a procedure that returns a cursor inside a procedure

    Hi,
    I have two stored procedures. They both return a cursor as output variables. On the other hand I have another stored procedure that calls these procedures and return their results again an output variable. I know that this seems quite odd to be wanting to do something like this but how can I do that?

    You can make the hack generic. Make it execute any SQL as that schema that creates the ref cursor. E.g.
    // as schema BILLY, open a huge security hole and grant access to USER1
    SQL> create or replace procedure GetTableData( tableName varchar2, refCur out sys_refcursor ) authid definer is
      2          dynamicSQL      varchar2(32767);
      3  begin
      4          dynamicSQL := 'select * from '||tableName;
      5          open refCur for dynamicSQL;
      6  end;
      7  /
    Procedure created.
    SQL>
    SQL>
    SQL> grant execute on GetTableData to USER1;
    Grant succeeded.As USER1, you can now execute SQL (and even PL/SQL) as BILLY:
    SQL> create or replace type TStrings is table of varchar2(4000);
      2  /
    Type created.
    SQL> grant execute on TStrings to BILLY;
    Grant succeeded.
    SQL> --// execute this as the caller (which will be BILLY.GetTableData)
    SQL> create or replace procedure ExecSQL( hackSQL varchar2 ) authid current_user is
      2          pragma autonomous_transaction;
      3  begin
      4          execute immediate hackSQL;
      5          commit;
      6  end;
      7  /
    Procedure created.
    SQL> --// wrap the above into something that BILLY.GetData can execute as a ref cursor
    SQL> --// and return a meaningful message as to how successful the hack was
    SQL> create or replace function PipeLineHack( hackSQL varchar2 ) return TStrings authid current_user pipelined is
      2  begin
      3          ExecSQL(  hackSQL );
      4          pipe row( 'SQL hack successful' );
      5  exception when OTHERS then
      6          pipe row( 'SQL hack faled with '||SQLERRM(SQLCODE) );
      7  end;
      8  /
    Function created.
    SQL>
    SQL> grant execute on PipeLineHack to BILLY;
    Grant succeeded.
    SQL>
    SQL> var c refcursor
    SQL> --// expected used of the GetTableData() interface
    SQL> --// we select from table BILLY.EMP
    SQL> exec BILLY.GetTableData( 'EMP', :c );
    PL/SQL procedure successfully completed.
    SQL> print c
         EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 1980/12/17 00:00:00        800          0         20
          7499 ALLEN      SALESMAN        7698 1981/02/20 00:00:00       1600        300         30
          7521 WARD       SALESMAN        7698 1981/02/22 00:00:00       1250        500         30
          7566 JONES      MANAGER         7839 1981/04/02 00:00:00       2975                    20
          7654 MARTIN     SALESMAN        7698 1981/09/28 00:00:00       1250       1400         30
          7698 BLAKE      MANAGER         7839 1981/05/01 00:00:00       2850                    30
          7782 CLARK      MANAGER         7839 1981/06/09 00:00:00       2450                    10
          7788 SCOTT      ANALYST         7566 1987/04/19 00:00:00       3000                    20
          7839 KING       PRESIDENT            1981/11/17 00:00:00       5000                    10
          7844 TURNER     SALESMAN        7698 1981/09/08 00:00:00       1500          0         30
          7876 ADAMS      CLERK           7788 1987/05/23 00:00:00       1100                    20
          7900 JAMES      CLERK           7698 1981/12/03 00:00:00        950                    30
          7902 FORD       ANALYST         7566 1981/12/03 00:00:00       3000                    20
          7934 MILLER     CLERK           7782 1982/01/23 00:00:00       1300                    10
    14 rows selected.
    SQL>
    SQL> --// getting that interface to run unexpected code - we
    SQL> --// rename BILLY.EMP table to something else
    SQL> exec BILLY.GetTableData( 'TABLE(USER1.PipeLineHack( ''alter table emp rename to emp_has_been_hacked''))', :c );
    PL/SQL procedure successfully completed.
    SQL> print c
    COLUMN_VALUE
    SQL hack successful
    SQL>

  • Restrictions while using ref cursor inside an xmltype

    Hi,
    Looks like that getclobVal() can't be used in select where select statement is ref cursor for xmltype.
    example
    SQL> select xmltype(cursor(select xmltype('<a>1</a>').getclobval() from dual)) from dual;
    select xmltype(cursor(select xmltype('<a>1</a>').getclobval() from dual)) from dual
    ERROR at line 1:
    ORA-03001: unimplemented feature
    ORA-22806: not an object or REF also doesn't work the following select
    SQL> select xmltype(cursor(select xmltype('<a>'||lpad('a',1,'a')||'</a>') from dual)) from dual;
    ERROR:
    ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00234: namespace prefix
    "XMLTYPE_x0028__x0027__x003C_A_x003E__x0027__x007C__x007C_LPAD_x0028_" is not
    declared
    Error at line 4
    ORA-06512: at "SYS.XMLTYPE", line 334
    ORA-06512: at line 1DB version 10.2.0.1
    Ants
    Message was edited by:
    Ants Hindpere

    I'm not sure if it is about datatypes per se. Looks to more of a restriction of the XMLTYPE object itself:
    SQL> select cursor (select xmltype ('<A>1</A>').getclobval () a from dual) from dual
    select cursor (select xmltype ('<A>1</A>').getclobval () a from dual) from dual
    Error at line 0
    ORA-03001: unimplemented feature
    ORA-22806: not an object or REF
    but astonishingly
    SQL> select cursor (select xmlelement(A, 1).getclobval () a from dual) from dual
    Cursor (A)
    <A>1</A> 

  • Moving the cursor inside a file being written.

    Is there any way to move the cursor to a specific location in a file that I am editing.
    for example:
    moveCursor(int row, int col)
    moveRight(int col)
    moveToEnd(); //Move to end of current rowI know that I can use RandomAccessFile but that only provides skipBytes(int), seek(long), and getFilePointer().
    Thanks,
    Marcus

    I don't know of anything like that in the api, but you could roll your own. You need to know the length of your lines (which I assume you do since it's a RAF). It'll also be easier to keep track of what row and col you're on, so you don't have to recompute it continually (this may not be true depending on the rest of your design).
    To move the cursor to a given row and col, you seek to (row * RECORD_LENGTH + col).
    To move right, just move the pointer ahead the difference between the current col and the given col.
    Moving to the end of the current row is the same as moving right, just with the last row specified.
    Add in some bounds checking to make sure you don't go past the end of a row, and you should be good.

  • Wait Cursor inside SAP Business One

    Hi All,
    Just wanna know if there's a way to set my cursor to wait cursor (magnifying glass) without using a progress bar?
    Thanks

    Hello,
    You can do only the wait cursor with the progressbar.
    Regards
    János

  • Send Multiple Attachments

    I'm not being lazy, I have looked through many of the threads and don't seems to be able to find the answer to this query, if anyone can offer any assistance I'd be very grateful.
    I want to send email with multiple attachments and I'm taking advantages of the demo_mail functionality already in place. I can successfully send email with and attachment by passing in the file name from the wwv.flows table after I've uploaded the file. The problem is that I'm not sure how to pass multiple attachments. I imagine I would either be passing multiple file names or combining the blobs?
    Code as follows:
    procedure email_attachments_asis(
    p_sender varchar2, -- sender, example: 'Me '
    p_recipients varchar2, -- recipients, example: 'Someone '
    p_subject varchar2, -- subject
    p_body varchar2, -- body
    p_filename varchar2, -- name of pdf file
    p_blob blob, -- file(s)
    p_mime_type varchar2,
    p_number_to_attach number) is
    conn utl_smtp.connection;
    i number;
    len number;
    v_eol VARCHAR2(2) := chr(13)||chr(10);
    BEGIN
    conn := demo_mail.begin_mail(
    sender => p_sender,
    recipients => p_recipients,
    subject => p_subject,
    mime_type => demo_mail.MULTIPART_MIME_TYPE);
    if p_number_to_attach > 1 then
    demo_mail.attach_text(
    conn => conn,
    data => p_body,
    mime_type => p_mime_type);
    elsif p_number_to_attach = 1 then
    demo_mail.attach_text(
    conn => conn,
    data => p_body,
    mime_type => p_mime_type);
    end if;
    for counter in 1..p_number_to_attach loop
    demo_mail.begin_attachment(
    conn => conn,
    mime_type => p_mime_type,
    inline => TRUE,
    filename => p_filename,
    transfer_enc => 'base64');
    -- split the Base64 encoded attachment into multiple lines
    i := 1;
    len := DBMS_LOB.getLength(p_blob);
    WHILE (i < len) LOOP
    IF(i + demo_mail.MAX_BASE64_LINE_WIDTH < len)THEN
    UTL_SMTP.Write_Raw_Data (conn
    , UTL_ENCODE.Base64_Encode(
    DBMS_LOB.Substr(p_blob, demo_mail.MAX_BASE64_LINE_WIDTH, i)));
    ELSE
    UTL_SMTP.Write_Raw_Data (conn
    , UTL_ENCODE.Base64_Encode(
    DBMS_LOB.Substr(p_blob, (len - i)+1, i)));
    END IF;
    UTL_SMTP.Write_Data(conn, UTL_TCP.CRLF);
    i := i + demo_mail.MAX_BASE64_LINE_WIDTH;
    END LOOP;
    end loop;
    demo_mail.end_attachment(conn => conn);
    demo_mail.end_mail( conn => conn );
    END email_attachments_asis;

    The method I would use is:
    1) Write a utility function that accepts a SQL cursor, converts it to XML and applies a XSL stylesheet to convert it to an HTML table and return the result as a CLOB. An example that I based code on is here. My modified example that accepts the stylesheet is at the end.
    2) For each report, run the function and attach it to the email.
    FUNCTION    FNCREFCURSOR2XML
    (  p_refCursor SYS_REFCURSOR,
       p_stlsht    CLOB,
       p_parms     VARCHAR2 default null)
    RETURN CLOB
    IS
    lRetVal      CLOB;
    lHTMLOutput  XMLType;
    lXMLData     XMLType;
    lContext     DBMS_XMLGEN.CTXHANDLE;
    stringarg    varchar2(200);
       BEGIN
       -- get a handle on the ref cursor --
       lContext := DBMS_XMLGEN.NEWCONTEXT(p_refCursor);
       -- setNullHandling to 1 (or 2) to allow null columns to be displayed --
       DBMS_XMLGEN.setNullHandling(lContext,1);
       -- create XML from ref cursor --
       lXMLData := DBMS_XMLGEN.GETXMLTYPE(lContext,DBMS_XMLGEN.NONE);
       if lXMLData is null then
         DBMS_XMLGEN.CLOSECONTEXT(lContext);
         close p_refCursor;
         return null;
       end if;
       DBMS_OUTPUT.PUT_LINE('xmldata = ' || lXMLData.getStringVal());
       -- XSL transformation to convert XML to HTML --
       --stringarg:=regexp_replace(p_parms,'"([[:alnum:][:space:]]*)"','"string(' || '''' || '\1' || '''' || ')"',1,0,'m');
       lHTMLOutput := lXMLData.transform(XMLType(p_stlsht),p_parms);
       -- convert XMLType to Clob --
       lRetVal := dbms_xmlgen.convert(lHTMLOutput.getClobVal(),DBMS_XMLGEN.ENTITY_DECODE );
       --lRetVal := lHTMLOutput.getClobVal();
       lRetVal := regexp_replace(lRetVal,'_x0020_',' ',1,0,'m');
       lRetVal := regexp_replace(lRetVal,'_x0026_','&',1,0,'m');
       lRetVal := regexp_replace(lRetVal,'_x003C_','<',1,0,'m');
       lRetVal := regexp_replace(lRetVal,'_x002F_','/',1,0,'m');
       lRetVal := regexp_replace(lRetVal,'_x003E_','>',1,0,'m');
       lRetVal := regexp_replace(lRetVal,'>','>',1,0,'m');
       lRetVal := regexp_replace(lRetVal,'<','<',1,0,'m');
       lRetVal := regexp_replace(lRetVal,'"','"',1,0,'m');
       lRetVal := regexp_replace(lRetVal,'&','&',1,0,'m');
       --lRetVal := lHTMLOutput.getStringVal();
       DBMS_XMLGEN.CLOSECONTEXT(lContext);
       CLOSE p_refCursor;
       RETURN lRetVal;
    end fncRefCursor2XML;-----
    Example Stylesheet:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html"/>
    <xsl:param name="title"/>
    <xsl:param name="widthpx"  />
    <xsl:param name="widthpct"  />
    <xsl:template match="/">
    <div style="width:100%">
       <table border="1px" class="t16standard" style="border-collapse:collapse">
    <xsl:if test="string-length($widthpx) > 0">
      <xsl:attribute name="width">
         <xsl:value-of select="$widthpx"/>px
      </xsl:attribute>
    </xsl:if>
    <xsl:if test="string-length($widthpct) > 0">
      <xsl:attribute name="width">
         <xsl:value-of select="$widthpct"/>%
      </xsl:attribute>
    </xsl:if>
      <xsl:if test='string-length($title) > 0 '>
         <tr>
           <th style="font-size:14px;background:#9DB8D2">
             <xsl:attribute name="colspan">
               <xsl:value-of select="count(/ROWSET/ROW[1]/*)"/>
             </xsl:attribute>
             <xsl:attribute name="align">center</xsl:attribute>
           <xsl:value-of select="translate($title,'_',' ')"/>
          </th>
         </tr>
      </xsl:if>
         <tr>
          <xsl:for-each select="/ROWSET/ROW[1]/*">
           <th class="t16ReportHeader"><xsl:value-of select="name()"/></th>
          </xsl:for-each>
         </tr>
         <xsl:for-each select="/ROWSET/*">
          <tr>
           <xsl:for-each select="./*">
            <td>
                   <xsl:choose>
                     <xsl:when test="string(@bgcolor)">
                       <xsl:attribute name="bgcolor">
                          <xsl:value-of select="@bgcolor" />
                       </xsl:attribute>
                     </xsl:when>
                     <xsl:otherwise>
    <xsl:attribute name="bgcolor">#FFFFFF</xsl:attribute>
                     </xsl:otherwise>
                   </xsl:choose>
                   <xsl:choose>
                     <xsl:when test="string(@style)">
                       <xsl:attribute name="style">
                          <xsl:value-of select="@style" />
                       </xsl:attribute>
                      </xsl:when>
                      <xsl:otherwise>
                       <xsl:attribute name="style">
                          padding:3px
                       </xsl:attribute>
                      </xsl:otherwise>
                    </xsl:choose>
                <xsl:value-of select="text()"/> </td>
           </xsl:for-each>
          </tr>
         </xsl:for-each>
       </table>
    </div>
    </xsl:template>
    </xsl:stylesheet>Edited by: Fairfax_Al on Apr 15, 2009 4:17 PM

  • Alias for Cursor ROWS  in DBMS_XMLGEN

    Gurus,
    I have following sample function to generate XML content
    ==========================================
    create or replace function getxmldata
    return clob is
    mysql DBMS_XMLGEN.ctxHandle;
    begin
    mysql := DBMS_XMLGEN.newContext('
    select cursor(select item_id as "@Item_Id",has_metal,has_stone from pid_item where item_id in (17)) as "ItemHeader"
    from dual
    dbms_xmlgen.setrowsettag(mysql,'ROOT');
    dbms_xmlgen.setrowtag(mysql,null);
    return(DBMS_XMLGEN.getXML(mysql));
    end;
    =======================================
    When i call this function as "select getxmldata from dual". I do get following output
    =======================================
    <?xml version="1.0"?>
    <ROOT>
    <ItemHeader>
    <ItemHeader_ROW Item_Id = "17">
    <HAS_METAL>N</HAS_METAL>
    <HAS_STONE>N</HAS_STONE>
    </ItemHeader_ROW>
    </ItemHeader>
    </ROOT>
    =======================================
    I want to have Item as Tag name instead of "ItemHeader_ROW" . Can you please let me know how can get this??
    Thanks
    srinivas.L

    Like this perhaps?
    Connected to:
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    set long 10000
    create or replace function getxmldata
    return clob is
      mysql DBMS_XMLGEN.ctxHandle;
    begin
    mysql := DBMS_XMLGEN.newContext(
      'select cursor(select * from dual) as "ItemHeader" from dual');
    dbms_xmlgen.setrowsettag(mysql,'ROOT');
    dbms_xmlgen.setrowtag(mysql,null);
    return
    ( replace
      ( DBMS_XMLGEN.getXML(mysql)
      , 'ItemHeader_ROW>'
      , 'Item>'
    end;
    Function created.
    show errors
    No errors.
    select getxmldata from dual ;
    GETXMLDATA
    <?xml version="1.0"?>
    <ROOT>
    <ItemHeader>
      <Item>
       <DUMMY>X</DUMMY>
      </Item>
    </ItemHeader>
    </ROOT>--
    Joe Fuda
    SQL Snippets

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

  • Setting Two Row Tags issue using DBMS_XMLGEN.setrowtag ?

    Hi All,
         Am generating a xml using DBMS_XMLGEN.
         I want to generate a XML in the following format
         <MAIN>
         <PACK = 1>
         <EMP DETAILS>
              Some data goes here     
         <EMP DETAILS>     
    <PACK = 2>
         <EMP DETAILS>
                   Some data goes here
         <EMP DETAILS>     
                   Some data goes here
         <EMP DETAILS>
                   Some data goes here
    <PACK = 3>
         <EMP DETAILS>
                   Some data goes here
         <EMP DETAILS>     
                   Some data goes here               
         <EMP DETAILS>
         <MAIN>
         Am able to set the only the following
         DBMS_XMLGEN.setrowsettag('xmlhandle','MAIN');
         DBMS_XMLGEN.setrowtag('xmlhandle','EMP DETAILS');
         But the problem is setting another row tag <PACK>
         Is it possible to set another rowtag ?
         Please any inputs on this will be really helpful?

    I don't think you can set two different row tags in dbms_xmlgen. I'm also not sure about the "= 1", "= 2", etc. strings in your PACK tags. Perhaps I'm missing something but that doesn't look like legal XML.
    Here's an approach that may help anyway though ...
    Connected to:
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    set echo on
    set long 10000
    set longchunksize 10000
    set pagesize 100
    create or replace type emp_details as object
    ( empno integer, ename varchar2(10) )
    Type created.
    create or replace function getxmldata return clob
    is
      mysql dbms_xmlgen.ctxHandle ;
      v_result clob ;
    begin
      mysql :=
        dbms_xmlgen.newContext
          'select emp_details( empno, ename ) as emp_details
          from emp where deptno = 10'
      dbms_xmlgen.setrowsettag(mysql,'MAIN');
      dbms_xmlgen.setrowtag(mysql,'PACK');
      v_result := dbms_xmlgen.getXML(mysql) ;
      dbms_xmlgen.closeContext( mysql );
      return( v_result );
    end;
    Function created.
    show errors
    No errors.
    select getxmldata from dual ;
    GETXMLDATA
    <?xml version="1.0"?>
    <MAIN>
    <PACK>
      <EMP_DETAILS>
       <EMPNO>7782</EMPNO>
       <ENAME>CLARK</ENAME>
      </EMP_DETAILS>
    </PACK>
    <PACK>
      <EMP_DETAILS>
       <EMPNO>7839</EMPNO>
       <ENAME>KING</ENAME>
      </EMP_DETAILS>
    </PACK>
    <PACK>
      <EMP_DETAILS>
       <EMPNO>7934</EMPNO>
       <ENAME>MILLER</ENAME>
      </EMP_DETAILS>
    </PACK>
    </MAIN>
    1 row selected.
    drop function getxmldata ;
    Function dropped.
    drop type emp_details ;
    Type dropped.--
    Joe Fuda
    SQL Snippets

Maybe you are looking for