Skip to Main Content
  • Questions
  • need to find out the output of a particular character from a string

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Ankur.

Asked: January 22, 2020 - 8:42 am UTC

Last updated: January 23, 2020 - 2:59 am UTC

Version: 10

Viewed 1000+ times

You Asked

Example String:

I01 I0102 TID6977105'


Above is the string from a file format.

Need the 7 digit number string after 'TID'

Example: 6977105


How to retrieve that one?

and Chris said...

You could use either regular expressions or substr/instr:

with rws as (
  select 'I01 I0102 TID6977105' str from dual
)
  select substr ( 
           regexp_substr ( str, 'TID([0-9]){7}' ), 4 
         ) regex,
         substr ( 
           str, instr ( str, 'TID' ) + 3, 7
         ) sub
  from   rws;

REGEX     SUB       
6977105   6977105  


The regex will only return TID followed by seven digits. Whereas substr/instr will return TID followed by any seven characters. So if you want to ensure you only return TID with exactly seven digits after, the regex is safer here.

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Solution is superb

palankur, January 22, 2020 - 6:52 pm UTC

Thanks a lot for your quick time solution. It's help a lot for implement this logic.
Connor McDonald
January 23, 2020 - 2:59 am UTC

glad we could help

More to Explore

SQL

The Oracle documentation contains a complete SQL reference.