0

I have

"This is <>sample<> text. Need to extract <>smth1<> and <>smth2<> and many others." in a column of oracle database. I need to get:

sample smth1 smth2

Any help?

1
  • 2
    you're really using Oracle 8? Commented Feb 14, 2013 at 13:02

3 Answers 3

1

try to create this function:

create or replace
Function GetSurroundedText (origStr varchar2, openingStr varchar2, closingStr varchar2, outputSep varchar2)
Return Varchar2
Is
   continue boolean := true;
   l_string Varchar2(2000) := origStr;
   startPos PLS_Integer;
   endPos PLS_Integer;
   openingStrPos PLS_Integer;
   res Varchar2(2000) := '';
   sep Varchar2(100) := outputSep;
Begin
While true
Loop
   openingStrPos :=Instr(l_string, openingStr);
   If openingStrPos > 0 Then
      startPos := openingStrPos + Length(openingStr);
      l_String := Substr(l_string, startPos);
   else
      exit;
   end if;
   endPos := Instr(l_string, closingStr);
   if endPos > 0 Then
      if res = '' Then
         sep := '';
      else
         sep := outputSep;
      end If;
      res := res || sep || Substr(l_string, 1, endpos-1);
      l_String := Substr(l_string, endPos + Length(closingStr));
   else
      exit;
   end if;
End Loop;
return res;
End;

And, in your case, use it like this:

select GetSurroundedText(mycolumn, '<>', '<>', ' ') from mytable;
Sign up to request clarification or add additional context in comments.

Comments

0

In Oracle/PLSQL, the replace function replaces a sequence of characters in a string with another set of characters.

replace( string1, string_to_replace, [ replacement_string ])

so

replace( YourString, '<>', '');

Should do the trick.

If your case is more complex and you need a more elaborated solution you can check this function that allow you extract words between delimiters.

http://www.oradev.com/parse_string.jsp

Hope it helps.

Comments

0

Use replace function to replace the <> to ''.It will work

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.