Solved

Oracle XMLTABLE XPath Substring

Posted on 2014-10-09
5
543 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 77

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 77

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
Via a live example, show how to take different types of Oracle backups using RMAN.

623 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