Regular expression to parse out numbers with optional precision.

March 29, 2012 at 10:26 am | Posted in Oracle Developement, PL/SQL | Leave a comment
Tags: , , , ,

This regular expression will parse out numbers with or without decimals. In this case, the number has to be surrounded by parenthesis () in order for the expression to work.


SELECT LTRIM(RTRIM(REGEXP_SUBSTR('&str', '\([[:digit:]]*\.?[[:digit:]]*\)'),')'),'(') RESULT FROM DUAL;

 

SQL> SELECT LTRIM(RTRIM(REGEXP_SUBSTR('&str', '\([[:digit:]]*\.?[[:digit:]]*\)'),')'),'(') RESULT FROM DUAL;
Enter value for str: The groceries cost (123.45) today.
RESULT
------
123.45
1 row selected.
SQL>
Advertisements

Leave a Comment »

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.
Entries and comments feeds.

%d bloggers like this: