Solved

RegExp oracle

Posted on 2015-02-08
5
132 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 77

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 38

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 77

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 38

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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.
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 shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

820 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