Solved

RegExp oracle

Posted on 2015-02-08
5
131 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)
ID: 40597386
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, EE MVE
ID: 40597391
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
ID: 40598162
thanks it is working.
0
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 40598196
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, EE MVE
ID: 40598308
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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
oracle report printing 2 pages in one page 2 68
SQL Query 34 99
su - oracle could not open session 6 74
Oracle - Query link database loop 8 38
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.  …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to recover a database from a user managed backup

770 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