【问题标题】:PL/SQL Regular expression not workingPL/SQL 正则表达式不起作用
【发布时间】:2016-07-07 08:56:28
【问题描述】:

我有以下代码:

declare
  l_input      clob;
  l_output     clob;
  function check_this_regex(
    io_str    in out clob
    ,o_found  out clob
  ) return boolean
  is
    l_match   clob;
  begin
    dbms_output.put_line('Matching against ->' || io_str || '<-');
    l_match := regexp_substr(io_str, '"((y)*)"');

    if l_match is null then
      return false;
    end if;

    o_found := l_match;
    return true;
  end;
begin
  l_input := to_clob('x');
  dbms_output.put_line('l_input->' || l_input || '<-');
  if (check_this_regex(l_input, l_output)) then
     dbms_output.put_line('Found: ' || l_output);
  else
     dbms_output.put_line('Not found');
  end if;
end;

为什么会输出Found

【问题讨论】:

    标签: regex oracle plsql


    【解决方案1】:

    问题应该是针对NULL检查一个clob;以这种方式编辑您的支票

    if l_match /* is null */ = empty_clob() then
    

    给:

    l_input->x<-
    Matching against ->x<-
    Not found
    

    【讨论】:

      【解决方案2】:

      clob 的 regexp_substr 总是返回非空值。检查示例。

      declare 
       v_clob clob;
       v_in clob :='a';
      
       v_str varchar2(10);
       v_st_in  varchar2(10) :='a';
      begin 
       v_clob := regexp_substr(v_in,'xx');
       if v_clob is null then
        dbms_output.put_line('aaa');
       end if;
       v_str := regexp_substr(v_st_in,'xx');
       if v_str is null then
        dbms_output.put_line('aaa');
       end if;
      end; 
      

      【讨论】:

        猜你喜欢
        • 2014-03-23
        • 2014-07-27
        • 2019-06-10
        • 1970-01-01
        • 2015-12-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多