Query to get only numbers from a string

前端 未结 14 2284
野性不改
野性不改 2020-11-22 06:17

I have data like this:

string 1: 003Preliminary Examination Plan   
string 2: Coordination005  
string 3: Balance1000sheet

The output I exp

相关标签:
14条回答
  • 2020-11-22 06:42

    Taking other answers into account, i came up with my own: Try this :

    SUBSTRING('your-string-here', PATINDEX('%[0-9]%', 'your-string-here'), LEN('your-string-here'))
    

    NB: Only works for the first int in the string, ex: abc123vfg34 returns 123.

    0 讨论(0)
  • 2020-11-22 06:43

    In Oracle

    You can get what you want using this:

    SUBSTR('ABCD1234EFGH',REGEXP_INSTR ('ABCD1234EFGH', '[[:digit:]]'),REGEXP_COUNT ('ABCD1234EFGH', '[[:digit:]]'))
    

    Sample Query:

    SELECT SUBSTR('003Preliminary Examination Plan  ',REGEXP_INSTR ('003Preliminary Examination Plan  ', '[[:digit:]]'),REGEXP_COUNT ('003Preliminary Examination Plan  ', '[[:digit:]]')) SAMPLE1,
    SUBSTR('Coordination005',REGEXP_INSTR ('Coordination005', '[[:digit:]]'),REGEXP_COUNT ('Coordination005', '[[:digit:]]')) SAMPLE2,
    SUBSTR('Balance1000sheet',REGEXP_INSTR ('Balance1000sheet', '[[:digit:]]'),REGEXP_COUNT ('Balance1000sheet', '[[:digit:]]')) SAMPLE3 FROM DUAL
    
    0 讨论(0)
提交回复
热议问题