Return Only number from a string if it contains numbers

后端 未结 3 1478
深忆病人
深忆病人 2021-01-28 07:21

For example,
string is abc123CD need to find out a method to read only numbers in the string
i.e.

  select a_postgres_function(\'a         


        
3条回答
  •  一生所求
    2021-01-28 08:02

    If you want to get all digit characters from the string (not just the first group), it is easier to remove all characters, which aren't a digit:

    select regexp_replace('abc123CD45ef', '[^\d]+', '', 'g');
    
    -- regexp_replace
    -- --------------
    --    '12345'
    

提交回复
热议问题