Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2007
    Posts
    65

    Unanswered: Extract number from string

    Hello to all.

    I'm new to sqlplus and trying to do the following:
    I have some strings that may be like 'ABC*9497' or 'ABCD*9497'. How can i extract just the numeric part (9497)? I've been trying to use TO_NUMBER function in a seriuos of formats but could not get it.
    Can someone please give some help? The number of characters up to the asterisk can vary.
    Thanks in advance for any kind help.
    Octavio

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    select substr('ABC*9497',(instr('ABC*9497','*')+1)) from dual;

    SUBS
    ----
    9497
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Jun 2007
    Posts
    65
    Anacedent, thanks a million.
    Octavio

  4. #4
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Or, using regular expressions:
    Code:
    SQL> with test as
      2    (select 'ABC*9497' col from dual union
      3     select 'ABCD*234' from dual
      4    )
      5  select col, regexp_substr(col, '\d+$') numbers_only
      6  from test;
    
    COL      NUMBERS_ONLY
    -------- --------------------------------
    ABC*9497 9497
    ABCD*234 234
    
    SQL>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •