Return Only number from a string if it contains numbers

后端 未结 3 1486
深忆病人
深忆病人 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:03

    Try this:

    select (regexp_matches('abc123CD', '\d+'))[1];
    

    Since regexp_matches returns array of text, you should access the first element by [1].

提交回复
热议问题