Solved

Oracle XMLTABLE XPath Substring

Posted on 2014-10-09
5
468 Views
Last Modified: 2014-10-09
I have an Oracle query:

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

Open in new window


It returns data like this:

ID_ATTRIBUTE       ID_MPGM_RULE
27049                      100030.0
100053                      100058.0
100055                      100058.2

I need to remove the .0 and .2 from the ID_MPGM_RULE.
0
Comment
Question by:Bob Learned
  • 3
  • 2
5 Comments
 
LVL 76

Accepted Solution

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

... trunc( ID_MPGM_RULE) ...
0
 
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.
0
 
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:

100022.4.1
100022.4.3

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

0
 
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.
0
 
LVL 76

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!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

867 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now