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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:48:33+00:00 2026-06-15T01:48:33+00:00

Imagine two tables sites & buildings , where a site may have multiple buildings.

  • 0

Imagine two tables sites & buildings, where a site may have multiple buildings. I have a query that generates an xml for geospacial data mapping, and trying to add all buildings that belong to a site, thought using LISTAGG function.

Working query prior to adding buildings

SELECT XMLELEMENT("rss", 
            XMLATTRIBUTES('http://www.georss.org/georss' AS "xmlns:georss"),
                    XMLELEMENT("channel",
                                 XMLAGG(XMLELEMENT("item",
                                                   XMLFOREST(title AS "title",
                                                              description AS "description",
                                                              point AS "georss:point"))))).EXTRACT('/*')
    FROM (SELECT trim(s.sitedesc) AS title, 
          'Employee Count: ' || s.sitefte || '. Bldg Gross SF: ' || s.bldgarea || '. ' || CASE WHEN s.leasestat = '0' THEN 'Owned' WHEN s.leasestat = '1' THEN 'Leased, end date: ' || trim(l.edate) END AS description, 
          trim(s.latitude) || ' ' || trim(s.longitude) AS point
          FROM site s, leases l
          WHERE s.sold <> 1
            AND s.longitude != ' '
            AND s.sitecode = l.sitecode
        )

I can get the LISTAGG function to work on it’s own.

SELECT LISTAGG(trim(b.bldgcode)||' '||trim(b.bldgdesc), ', ') WITHIN GROUP (ORDER BY b.bldgcode) AS Bldgs
FROM buildings b, sites s
WHERE b.sitecode = s.sitecode
GROUP BY s.sitedesc

However the GROUP BY clause throws an error in the xml “not a group by expression” (which I was expecting but can’t seem to fix). Sample below, Is it possible to use LISTAGG within the XMLELEMENT ?

SELECT XMLELEMENT("rss", 
            XMLATTRIBUTES('http://www.georss.org/georss' AS "xmlns:georss"),
                    XMLELEMENT("channel",
                                 XMLAGG(XMLELEMENT("item",
                                                   XMLFOREST(title AS "title",
                                                              description AS "description",
                                                              point AS "georss:point"))))).EXTRACT('/*')
    FROM (SELECT trim(s.sitedesc) AS title, 
          'Employee Count: ' || s.sitefte || '. Bldg Gross SF: ' || s.bldgarea || '. ' || CASE WHEN s.leasestat = '0' THEN 'Owned' WHEN s.leasestat = '1' THEN 'Leased, end date: ' || trim(l.edate) END || LISTAGG(trim(b.bldgcode)||' '||trim(b.bldgdesc), ', ') WITHIN GROUP (ORDER BY b.bldgcode) AS description, 
          trim(s.latitude) || ' ' || trim(s.longitude) AS point
          FROM site s, lease l, buildings b
          WHERE s.sold <> 1
            AND s.longitude != ' '
            AND s.sitecode = l.sitecode
            AND b.sitecode = s.sitecode
          GROUP BY s.sitedesc
        )

Desired XML sample

<rss xmlns:georss="http://www.georss.org/georss">
<channel>
    <item>
        <title>SITE DESCRIPTION</title>
        <description>Employee Count: ###. Bldg Gross SF: ####. Owned/Leased Building1, building2, etc.</description>
        <georss:point>LAT LON</georss:point>
    </item>
....
</channel>
</rss>
  • 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-15T01:48:35+00:00Added an answer on June 15, 2026 at 1:48 am

    change your group by.

    select xmlelement("rss", xmlattributes('http://www.georss.org/georss' as "xmlns:georss"), xmlelement("channel", xmlagg(xmlelement("item", xmlforest(title as "title", description as "description", point as "georss:point")))))
           .extract('/*')
      from (select trim(s.sitedesc) as title,
                    'Employee Count: ' || s.sitefte || '. Bldg Gross SF: ' || s.bldgarea || '. ' || case
                      when s.leasestat = '0' then
                       'Owned'
                      when s.leasestat = '1' then
                       'Leased, end date: ' || trim(l.edate)
                    end || listagg(trim(b.bldgcode) || ' ' || trim(b.bldgdesc), ', ') within group(order by b.bldgcode) as description,
                    trim(s.latitude) || ' ' || trim(s.longitude) as point
               from site s, lease l, buildings b
              where s.sold <> 1
                and s.longitude != ' '
                and s.sitecode = l.sitecode
                and b.sitecode = s.sitecode
              group by s.sitedesc, s.sitefte, s.bldgarea, s.leasestat, l.edate, s.latitude, s.longitude)
    

    this should then work ok.

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

Sidebar

Related Questions

Imagine that we have two tables as follows: Trades ( TradeRef INT NOT NULL,
Imagine we have two tables in the database, user (FK id_role) and role (PK
Imagine that I have a form in a flash application with two fields, input1
So imagine you have the following two tables: CREATE movies ( id int, name
Imagine I have two tables in a DB like so: products: product_id name ----------------
Imagine you have two tables table: name table: keyword id name nameId keyword 1
I have a query that is supposed to pull records from several tables using
Imagine you have two tables, with a one to many relationship. For this example,
So imagine i have two tables, Car and Driver, with respectively these structure :
I have following two tables 1. publisher_site_regionwise_adratio publisher_id | site | region | ad_ratio

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.