Home » SQL & PL/SQL » SQL & PL/SQL » Sql Query between String
Sql Query between String [message #648217] Thu, 18 February 2016 10:25 Go to next message
sumit.cse07
Messages: 2
Registered: February 2016
Location: Bangalore
Junior Member
Hi All,

Please help me with the below problem -

I have input string as - "From: Other Unlisted - ABC Software To: Other Unlisted - ABC Software; From: Adm 1.2.0 To: Select One;"

Please help me with a query that will get the output as "From: Other Unlisted - ABC Software From: Adm 1.2.0"

Basically what I need is any string that is having "From:" and not any "To:"

Thanks
Re: Sql Query between String [message #648218 is a reply to message #648217] Thu, 18 February 2016 10:38 Go to previous messageGo to next message
Michel Cadot
Messages: 68776
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

SQL> with
  2    data as (
  3      select 'From: Other Unlisted - ABC Software To: Other Unlisted - ABC Software; From: Adm 1.2.0 To: Select One;'
  4             str
  5      from dual
  6    )
  7  select regexp_replace(str,'To:[^;]*;','') new_str
  8  from data
  9  /
NEW_STR
-----------------------------------------------------
From: Other Unlisted - ABC Software  From: Adm 1.2.0

Re: Sql Query between String [message #648219 is a reply to message #648218] Thu, 18 February 2016 10:49 Go to previous messageGo to next message
sumit.cse07
Messages: 2
Registered: February 2016
Location: Bangalore
Junior Member
Thanks Michel.

Also can you please help to get the To: part as well.
"To: Other Unlisted - ABC Software To: Select One"

Thanks
Re: Sql Query between String [message #648220 is a reply to message #648219] Thu, 18 February 2016 11:04 Go to previous message
Michel Cadot
Messages: 68776
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

SQL> with
  2    data as (
  3      select 'From: Other Unlisted - ABC Software To: Other Unlisted - ABC Software; From: Adm 1.2.0 To: Select One;'
  4             str
  5      from dual
  6    )
  7  select regexp_replace(str,'From:.*?To:','To:') new_str
  8  from data
  9  /
NEW_STR
--------------------------------------------------
To: Other Unlisted - ABC Software; To: Select One;

Previous Topic: Retrieve specified characters from LONG datatype
Next Topic: Access variables from different script
Goto Forum:
  


Current Time: Thu Jun 25 15:14:16 CDT 2026