从数据库中select into 到变量V_name 类型varchar2(150),如何判断出V_name中是否包含了“任三”字符串?
例如 V_name = '人力资源部门_任三_离职',我如何判断出该字符串中包含“任”或者“任三”

解决方案 »

  1.   

    SELECT instr('abc', 'a') FROM dual
    出来1,表明abc含有a,并且再第一个位置
      

  2.   

    SQL> select * from test where name like '%1%' or name like '%3.%';        ID NAME
    ---------- ----------
             1 1.2
             3 3.7SQL> select * from test;        ID NAME
    ---------- ----------
             1 1.2
             2 2
             2 2.0
             3 3.7判断包含2或者包含3.的记录
      

  3.   

    if instr(V_name,'任三') > 0 then
      

  4.   

    declare
       V_name varchar2(150);
    begin
      V_name := '人力资源部门_任三_离职';
      
      if instr(V_name,'任三') > 0 then  
        DBMS_OUTPUT.PUT_LINE('有');   
      else 
         DBMS_OUTPUT.PUT_LINE('无');   
      end if;
    end;
    /
      

  5.   

    declare
    V_name varchar2(100);
    begin
    V_name := '人力资源部门_任三_离职';if instr(V_name,'任三') > 0 then
    DBMS_OUTPUT.PUT_LINE('有');
    else
    DBMS_OUTPUT.PUT_LINE('无');
    end if;
    end;
    /