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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:58:59+00:00 2026-06-11T18:58:59+00:00

I have a table (Oracle 11.2.0.2) with an xmltype column and other non-xmltype columns.

  • 0

I have a table (Oracle 11.2.0.2) with an xmltype column and other non-xmltype columns. I want to do a select based on the value of some of the non-xmltype columns plus the contents of the xmltype column.

I’ve tried doing this using xmlquery in my select, but I’m getting some funny results. Here’s a reduced version my data: an order table with the username and the order details.

-- create order table
create table orders(username varchar2(20), order_data xmltype);

-- an order entered by jim
insert into orders values ('jim', xmltype('
<ord:order xmlns:ord="http://www.blah.com/order/1.0">
   <ord:zip>123</ord:zip>
   <ord:date_time>2012-09-24T00:27:00</ord:date_time>
   <ord:item>
      <ord:product>A</ord:product>
      <ord:quantity>12</ord:quantity>
   </ord:item>
   <ord:item>
      <ord:product>B</ord:product>
      <ord:quantity>34</ord:quantity>
   </ord:item>
</ord:order>'));

-- an order entered by bob
insert into orders values ('bob', xmltype('
<ord:order xmlns:ord="http://www.blah.com/order/1.0">
   <ord:zip>123</ord:zip>
   <ord:date_time>2012-09-24T00:27:00</ord:date_time>
   <ord:item>
      <ord:product>A</ord:product>
      <ord:quantity>56</ord:quantity>
   </ord:item>
   <ord:item>
      <ord:product>C</ord:product>
      <ord:quantity>78</ord:quantity>
   </ord:item>
</ord:order>'));

As an example query, I tried to find all orders entered by Bob which have more than 1 item by doing this:

SELECT username, itemcount
FROM
  (SELECT username,
    XMLCAST(XMLQUERY('count(/*:order/*:item)' PASSING order_data RETURNING CONTENT) AS  NUMBER) itemcount
  FROM orders
  )
WHERE username = 'bob'
AND itemcount > 1

but it doesn’t return any results, however if I comment out the last line (AND itemcount > 1) I get:

username | linecount
--------------------
bob      |         2

…I’m not sure why that is, I thought maybe it wasn’t treating it as the correct type but I’m casting it as a number with the xmlcast.

What’s more puzzling is if I set the last line to be:

AND itemcount = 2

…it disappears again, but if I change it to:

AND itemcount != -7

…it reappears in the results, but with a value of zero:

username | linecount
--------------------
bob      |         0

So, I’m puzzled – I must be doing something wrong but I can’t see what it is.

I’ve found a workaround using xmltable which works fine, so that’ll do me:

SELECT username, X.*
FROM orders,
  XMLTABLE ( 
      xmlnamespaces ('http://www.blah.com/order/1.0' AS "ord" ),
      '/ord:order' PASSING order_data
          COLUMNS 
              itemcount number PATH 'count(ord:item)' ) AS X
WHERE username = 'bob'
AND itemcount > 1
  • 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-11T18:59:00+00:00Added an answer on June 11, 2026 at 6:59 pm

    I think this is an Oracle bug. It works fine for me on 11.2.0.1, but fails just like you describe on 11.2.0.2. I looked at My Oracle Support but couldn’t find anything. You may need to contact Oracle support for help resolving this problem.

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

Sidebar

Related Questions

I have an oracle table with a column from type SYS.XMLTYPE and a storage
I have an oracle table with nested tables in some of the columns. Now,
I have a table in Oracle with a VARCHAR column called DESCRIPTION. Some of
I have a table in Oracle called quotes with two columns: date and value
I have a table in Oracle and I want to select all the duplicated
I have an Oracle table with two columns ID and START_DATE, I want to
I am using XMLType column in some of my oracle database table. Earlier(in 11.2.0.2)
I have a table in Oracle where one of the column contains UserIds which
I have a table in Oracle 11.2 database. I want the database to run
I have a oracle table A which contains a column A.a which used to

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.