Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9291371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:37:47+00:00 2026-06-18T20:37:47+00:00

Using Oracle PLSQL, I have arrived at a point where i have generated a

  • 0

Using Oracle PLSQL, I have arrived at a point where i have generated a number of XML fragments of type XMLType. I have these stored in a VARRAY of type XMLTYPE. I can successfully print these out individually to a file.

What I want to do next is fuse all these fragments together and wrap them in another root element to generate a single document. From what I have read if I can get hold of an XMLSEQUENCETYPE then I can just pass this into XMLCONCAT(..) and it should return an XMLType concatenation of all the fragments. After this it’d just be a case of adding the root elements using XMLELEMENT(..). I am however, having difficulty finding a way of generating an XMLSEQUENCETYPE from my VARRAY of XMLTYPE.

Does anyone know how this can be done, and whether in fact the approach I have taken is the best one? (If anyone is curious, I’m trying to create a basic dbunit type framework. The intention of this script is to create a tool which can be used to output XML DataSets to file, which later get loaded into unit tests).

Here’s the plsql script:


set serveroutput on;
CREATE OR REPLACE TYPE rowset_query_type AS OBJECT ( 
   table_name          VARCHAR2(100),
   query_string        VARCHAR2(1024)
);
/

DECLARE

  TYPE XML_Fragments_Type IS VARRAY(1000) OF XMLTYPE;
  TYPE Rowset_Query_List_Type is VARRAY(1000) OF rowset_query_type;

  outputDir                 VARCHAR(200)  :=  'ORACLE_FILE_DIR';
  outputFile                VARCHAR(200)  :=  'TestDataSet.xml';

  qryCtx                    DBMS_XMLGEN.ctxHandle;
  rowsetResultFragments     XML_Fragments_Type;
  rowsetQueries             Rowset_Query_List_Type;  
  xmlResult                 xmltype;  
  rowsetQueryElement        rowset_query_type; 

  output                     CLOB;
BEGIN

 dbms_output.put_line('Exporting dataset...');

 -- export files to data fixture 

 -- define fixtures
 rowsetQueries := Rowset_Query_List_Type();
 rowsetQueries.EXTEND(2);

 rowsetQueries := Rowset_Query_List_Type(
 rowset_query_type('person', 'select * from person'),
 rowset_query_type('address','select * from address'));

 rowsetResultFragments := XML_Fragments_Type();
 rowsetResultFragments.EXTEND(rowsetQueries.count);

 FOR i IN rowsetQueries.FIRST..rowsetQueries.LAST 
 LOOP

  rowsetQueryElement := rowsetQueries(i);  
  dbms_output.put_line('Extracting dataset for table: ' || rowsetQueryElement.table_name || ' using query: ''' || rowsetQueryElement.query_string || '''');


  qryCtx := dbms_xmlgen.newContext(rowsetQueryElement.query_string);

  -- wrap the result up with a metadata tag containing the fixture tablename
  select xmlelement(
          "ROWSET_QUERY",
          xmlattributes(rowsetQueryElement.table_name as "tableName"),
              DBMS_XMLGEN.getXMLType(qryCtx)  
      )
  into rowsetResultFragments(i)
  from dual;

  --close context
  DBMS_XMLGEN.closeContext(qryCtx);

  -- print the results to console
  -- serialize the result for printing to output
  SELECT XMLSERIALIZE(
    CONTENT 
      rowsetResultFragments(i) 
    AS CLOB)
  INTO output
  FROM DUAL;

  DBMS_OUTPUT.PUT_LINE(output);

 END LOOP;




 -- concatenate the set of rowsetQueries result fragments to a single result clob
 --  ???

END;
/
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T20:37:48+00:00Added an answer on June 18, 2026 at 8:37 pm

    you’re almost there.

    first, change your type to an SQL one:

    create or replace TYPE XML_Fragments_Type IS VARRAY(1000) OF XMLTYPE;
    /
    

    then do this

    -- concatenate the set of rowsetQueries result fragments to a single result clob
     --  ???
    
     select xmlelement("root" ,xmlagg(column_value))
       into xmlresult
       from table(rowsetResultFragments);
    

    eg:

        SQL> create or replace TYPE XML_Fragments_Type IS VARRAY(1000) OF XMLTYPE;
          2  /
    
        Type created.
    
        SQL> DECLARE
          2
          3    --TYPE XML_Fragments_Type IS VARRAY(1000) OF XMLTYPE;
          4    TYPE Rowset_Query_List_Type is VARRAY(1000) OF rowset_query_type;
          5
          6    outputDir                 VARCHAR(200)  :=  'ORACLE_FILE_DIR';
          7    outputFile                VARCHAR(200)  :=  'TestDataSet.xml';
          8
    ...
         26   rowsetQueries := Rowset_Query_List_Type(
         27   rowset_query_type('person', 'select table_name, owner from dba_tables where rownum = 1'),
         28   rowset_query_type('address','select owner, type_name, attributes from dba_types where rownum = 1'));
         29
    ...
         56
         57   select xmlelement("root" ,xmlagg(column_value))
         58     into xmlresult
         59     from table(rowsetResultFragments);
         60    SELECT XMLSERIALIZE(
         61      CONTENT
         62        xmlresult
         63      AS CLOB )
         64    INTO output
         65    FROM DUAL;
         66    DBMS_OUTPUT.PUT_LINE(output);
         67
         68
         69  END;
         70  /
        Exporting dataset...
        Extracting dataset for table: person using query: 'select table_name, owner from dba_tables where rownum = 1'
        Extracting dataset for table: address using query: 'select owner, type_name, attributes from dba_types where rownum = 1'
        <root>
          <ROWSET_QUERY tableName="person">
            <ROWSET>
              <ROW>
                <TABLE_NAME>ICOL$</TABLE_NAME>
                <OWNER>SYS</OWNER>
              </ROW>
            </ROWSET>
          </ROWSET_QUERY>
          <ROWSET_QUERY tableName="address">
            <ROWSET>
              <ROW>
                <OWNER>CTXSYS</OWNER>
                <TYPE_NAME>CATINDEXMETHODS</TYPE_NAME>
                <ATTRIBUTES>3</ATTRIBUTES>
              </ROW>
            </ROWSET>
          </ROWSET_QUERY>
        </root>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Oracle 11g, and I have a lot of stored procedure code
I'm using Oracle 11g ( 11.1.0.7.0 ) and I have to create a XML
Using oracle database. Here's how i think the SQLException happens... Say i have two
I'm using Oracle 10.2 and have the following query: select h.company, count(*) from history
I'm using oracle 11g sql developer I have a varchar2 column with dates as
I'm using Oracle PL/SQL developer. I have two databases live and dummy. I have
Does anyone have any frameworks/apps/methodologies for creating Unit tests with Oracle?. I'm using Oracle
I m working on a project using oracle client and plsql for testing optimizing
I'm writing code using Oracle SQL Developer. I have a simple select statement that
I am using Oracle Sql Developer I have a huge script that creates tables,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.