2

Simple Question

I have the following type of results in a string field

'Number=123456'
'Number=1234567'
'Number=12345678'

How do I extract the value from the string with regard that the value can change between 5-8 figures

So far I did this but I doubt that fits my requirement

SELECT substring('Size' from 8 for ....

If I can tell it to start from the = sign till the end that would help!

4 Answers 4

3

The likely simplest solution is to trim 7 leading characters with right():

right(str, -7)

Demo:

SELECT str, right(str, -7)
FROM (
   VALUES ('Number=123456')
        , ('Number=1234567')
        , ('Number=12345678')
   ) t(str);

       str       |  right
-----------------+----------
 Number=123456   | 123456
 Number=1234567  | 1234567
 Number=12345678 | 12345678
Sign up to request clarification or add additional context in comments.

Comments

2

You could use REPLACE:

SELECT col, REPLACE(col, 'Number=', '')
FROM tab;

DBFiddle Demo

Comments

2

Based on this question: Split comma separated column data into additional columns

You could probably do the following:

SELECT *, split_part(col, '=', 2)
FROM table;

Comments

2

You may use regexp_matches :

with t(str) as
(
 select 'Number=123456'   union all 
 select 'Number=1234567'  union all
 select 'Number=12345678' union all
 select 'Number=12345678x9' 
)
select t.str  as "String", 
       regexp_matches(t.str, '=([A-Za-z0-9]+)', 'g')  as "Number"
  from t;

String            Number
--------------    ---------
Number=123456     123456
Number=1234567    1234567
Number=12345678   12345678
Number=12345678x9 12345678x9 
--> the last line shows only we look chars after equal sign even if non-digit

Rextester Demo

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.