Oracle XMLTABLE XPath Substring

Posted on 2014-10-09
Medium Priority
Last Modified: 2014-10-09
I have an Oracle query:

SELECT cxm.*
FROM t_mpgm_rule r,
              PASSING r.rule_xml
              COLUMNS id_attribute PATH '@AttributeID',
                      id_mpgm_rule PATH '@ID'
          ) cxm    

Open in new window

It returns data like this:

27049                      100030.0
100053                      100058.0
100055                      100058.2

I need to remove the .0 and .2 from the ID_MPGM_RULE.
Question by:Bob Learned
  • 3
  • 2
LVL 78

Accepted Solution

slightwv (䄆 Netminder) earned 2000 total points
ID: 40371655
Any number of ways.  Main ones that come to mind:   TRUNC and FLOOR

... trunc( ID_MPGM_RULE) ...
LVL 96

Author Comment

by:Bob Learned
ID: 40371718
The type for that column is XMLTYPE, so the type from the PATH '@ID' appears to be a string, since I get an ORA-07122: invalid number trying to use TRUNC or FLOOR.  If I try to cast it to a number, and I get the same error.
LVL 96

Author Comment

by:Bob Learned
ID: 40371749
I see where the problem is.  I thought the data was numeric, too, but there are a few values like this:


I used this expression to get the correct value:

SUBSTR(cxm.id_mpgm_rule, 1, INSTR(cxm.id_mpgm_rule, '.') - 1)

Open in new window

LVL 96

Author Closing Comment

by:Bob Learned
ID: 40371759
I figured this one out myself, but with a little help from my friend.  The comment got me to investigate the data in more detail.
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40372048
Guess I went to dinner at the right time!
Glad to be of very little assistance!

Miss crossing paths with you from time to time as a Badger!

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question