Solved

RegExp oracle

Posted on 2015-02-08
5
127 Views
Last Modified: 2015-02-09
Hi I have a requirement to write a query to just only retrieve number i
tried regexp_substr but no luck.


example data

1.1.test
1.2.testtt
1.3.tetsttt

i want to get only the number but not the string
the string should be eliminated.
please help
thanks.
0
Comment
Question by:Sarma Vadlamani
  • 2
  • 2
5 Comments
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
If the expected results are:
1.1
1.2
1.3

Try this:
rtrim(regexp_substr(col1,'^[0-9.]*'),'.')
0
 
LVL 37

Expert Comment

by:Gerwin Jansen
Comment Utility
Try this:

select regexp_substr ('1.3.tetsttt','[0-9]*\.[0-9]*') from dual;

result:

1.3

http://sqlfiddle.com/#!4/d41d8/40499
0
 

Author Comment

by:Sarma Vadlamani
Comment Utility
thanks it is working.
0
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
Comment Utility
If the data is always as you have posted and you want everything up to the second period, this might be more efficient (regular expressions are an expensive operation):

substr(col1,1,instr(col1,'.',1,2)-1)
0
 
LVL 37

Expert Comment

by:Gerwin Jansen
Comment Utility
Great ;) Which solution was working when you wrote the thanks comment? You chose the comment after that one as a solution?
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.

Join & Write a Comment

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
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

763 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

12 Experts available now in Live!

Get 1:1 Help Now