Solved

Oracle XMLTABLE XPath Substring

Posted on 2014-10-09
5
459 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

706 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