我有过
“这是<>sample<>文本。需要提取<>smth1<>和<>smth2<>以及许多其他内容。”在oracle数据库列中。我需要得到:
示例smth1 smth2
有什么帮助吗?
发布于 2013-02-15 23:51:11
尝试创建此函数:
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;在你的例子中,像这样使用它:
select GetSurroundedText(mycolumn, '<>', '<>', ' ') from mytable;发布于 2013-02-14 17:54:40
在Oracle/PLSQL中,replace函数将字符串中的一系列字符替换为另一组字符。
replace( string1, string_to_replace, [ replacement_string ])所以
replace( YourString, '<>', '');应该能行得通。
如果您的情况更复杂,并且需要更详细的解决方案,您可以检查此函数,该函数允许您在分隔符之间提取单词。
http://www.oradev.com/parse_string.jsp
希望能有所帮助。
发布于 2013-02-15 13:28:08
使用replace函数将<>替换为‘’。
https://stackoverflow.com/questions/14871801
复制相似问题