0

I have a string which contains alpha numeric characters. If the string had a decimal value then only i want to fetch decimal value from a string otherwise return blank.

I tried regular expression which is giving both numbers and decimals REGEXP_SUBSTR(string_value, '[0-9][.0-9]+')

Please find below sample data.

Example 1: My string is "182 test 123423". In this there is no decimal value then i need to return blank

Example 2: My string is "Test01.1%Ter 230334" and output should be 01.1

Example 3: My string is "14.05 get fvfdf 2434 Rf" and output should be 14.05

Please suggest me where i am doing wrong.

1 Answer 1

2

Your current attempt is almost correct, but the regex pattern is slightly off. Try this version:

SELECT
    REGEXP_SUBSTR(string_value, '[0-9]+\.[0-9]+')
FROM yourTable;

screen capture of demo below

Demo

Here is an explanation of the regex pattern:

[0-9]+   match one or more digits
\.       followed by a literal decimal point (which should be escaped)
[0-9]+   followed by one or more digits
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.