Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Extract text from column between two words

User_Z3XHFSep 13 2022

Hello. I need to extract text from table in column with where clausule. I found solution in T-SQL but i dont know how to translate for SQL Oracle

CREATE FUNCTION dbo.str_between(@col varchar(max), @start varchar(50), @end varchar(50))  
  RETURNS varchar(max)  
  WITH EXECUTE AS CALLER  
AS  
BEGIN  
  RETURN substring(@col, charindex(@start, @col) + len(@start), 
         isnull(nullif(charindex(@end, stuff(@col, 1, charindex(@start, @col)-1, '')),0),
         len(stuff(@col, 1, charindex(@start, @col)-1, ''))+1) - len(@start)-1);
END;  

its look like this but need to declare a text to search 

DECLARE @a VARCHAR(MAX) = 'All I knew was that the dog had been very bad and required harsh punishment immediately regardless of what anyone else thought.'
SELECT dbo.str_between(@a, 'the dog', 'immediately')
-- Yields' had been very bad and required harsh punishment '

how to translate to SQL orcl and extract data from table with column 'examplecolum' not delcared varchar like above and add a where clausule to it its possible?
This post has been answered by mathguy on Sep 15 2022
Jump to Answer
Comments
Post Details
Added on Sep 13 2022
19 comments
6,072 views