【问题标题】:oracle 8 extract strings from stringoracle 8 从字符串中提取字符串
【发布时间】:2013-02-14 09:41:29
【问题描述】:

我有

"这是 sample 文本。需要提取 smth1 和 smth2 以及许多其他内容。" 在 oracle 数据库的列中。 我需要得到:

样本 smth1 smth2

有什么帮助吗?

【问题讨论】:

  • 您真的在使用 Oracle 8?

标签: oracle extract subst


【解决方案1】:

尝试创建这个函数:

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;

【讨论】:

    【解决方案2】:

    在 Oracle/PLSQL 中,replace 函数将字符串中的一系列字符替换为另一组字符。

    replace( string1, string_to_replace, [ replacement_string ])
    

    所以

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

    应该做的伎俩。

    如果您的情况更复杂并且您需要更详细的解决方案,您可以检查此功能,该功能允许您在分隔符之间提取单词。

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

    希望对你有帮助。

    【讨论】:

      【解决方案3】:

      使用替换功能将替换为''。它会起作用

      【讨论】:

        猜你喜欢
        • 2019-07-23
        • 2021-01-29
        • 2019-02-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-21
        相关资源
        最近更新 更多