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 118095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:26:26+00:00 2026-05-11T03:26:26+00:00

I have a query that I am generating the XML from in Oracle using

  • 0

I have a query that I am generating the XML from in Oracle using the DBMS_XMLGEN package.

As an example, I am using a cursor as follows:

SELECT    A.NAME primaryName,    (CURSOR(SELECT B.NAME AS NAME FROM B WHERE B.ID=A.ID)) SYNONYMS FROM   A  

I have a query context, qtx, and set the query to the above for that context. Calling:

result := DBMS_XMLGEN.getXML(qryCtx); 

gets me almost where I want to be, from the viewpoint of the generated XML:

<PRIMARYNAME>Main Name</PRIMARYNAME>   <SYNONYMS>    <SYNONYMS_ROW>     <NAME>Synonym1</NAME>    </SYNONYMS_ROW>    <SYNONYMS_ROW>     <NAME>Synonym2</NAME>    </SYNONYMS_ROW>   </SYNONYMS> 

What I would really like to do is suppress the SYNONYMS_ROW tag. I’ve also tried a (CAST(MULTISET( <query>) and have similar results.

I know I could do a CLOB search and replace, but it seem like there should be a slightly easier or better engineered approach (ie, should I define the desired xsd and use that somehow?). I could also do a full stored procedure and build the tags as needed on the fly using cursors, but it would be nice to have a single SQL statement to use instead. Thanks for any suggestions

Thanks Nick – it turned out that the easiest way to solve the issue I describe was to use the XMLAGG function and generate my XML result slightly differently.

select    XMLELEMENT('primaryName',A.Name),    xmlelement('synonyms',        (SELECT XMLAGG(XMLELEMENT('name',b.name) ) from b         where b.id=a.id and b.type='S') ) from    A 
  • 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. 2026-05-11T03:26:26+00:00Added an answer on May 11, 2026 at 3:26 am

    You’ll need to drop down to PL/SQL where you have more control over the dbms_xmlgen package. For instance, here is how you can change the behavior of the row tags it sets.

    declare qryctx DBMS_XMLGEN.ctxhandle; results xmltype; begin    qryctx := dbms_xmlgen.newcontext('select foo from bar where id = my_id');   dbms_xmlgen.SETBINDVALUE(qryctx,'my_id',id);     dbms_xmlgen.setRowTag(qryCtx,NULL);     dbms_xmlgen.setRowSetTag(qryCtx,NULL);   results := dbms_xmlgen.getxmltype(qryctx);   dbms_xmlgen.closecontext(qryctx);   return results; end; 

    This package will allow you not only to change the row tag, but also the tag that goes around all the rows. In the above example, I suppressed the row tag by passing NULL as the second arguement into the dbms_xmlgen.setRowTag call. I hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query that originally looks like this: select c.Id, c.Name, c.CountryCode, c.CustomerNumber,
I have a query that I'm executing from a .NET application to a SQL
I have a query that is currently using a correlated subquery to return the
I have a query that pulls up questions from one table and answers from
I have a stored procedure which returns XML to the caller using a SELECT
I have a query that outputs address order data: SELECT ordernumber , article_description ,
I have a query that is created in VBA and selects column information from
I have a query that is dynamically built after looking up a field list
I have a query that looks like this: public IList<Post> FetchLatestOrders(int pageIndex, int recordCount)
I have a query that has 7 inner joins (because a lot of the

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.