Oracle自定義函式檢視2個字串是否匹配

derekzhan發表於2010-08-06
FUNCTION strContain(str1 IN VARCHAR2, str2 IN VARCHAR2)
    RETURN NUMBER IS
    Result     NUMBER;
   
    var_str1Index number;
    var_str2Index number;
    var_str1     type_split;
    var_str2     type_split;
    var_str1Split  varchar2(100);
    var_str2Split  varchar2(100);
BEGIN
    Result     := 0;
    
    --先拆分字串
    var_str1 := split_str(str1,',');
    var_str2 := split_str(str2,',');
    
    var_str1Index :=var_str1.first;
    var_str2Index :=var_str2.first;
    --在迴圈的逐個比較
    while (var_str1Index is not null) loop
       var_str1Split :=   var_str1(var_str1Index);
       dbms_output.put_line(var_str1Index||'-->'||var_str1Split);
       while (var_str2Index is not null ) loop
           var_str2Split := var_str2(var_str2Index);
           dbms_output.put_line(var_str2Index ||'==>'||var_str2Split);
           if(var_str1Split = var_str2Split) then
               return 1;              
           end if;            
           var_str2Index :=var_str2.next(var_str2Index);
       end loop;
       var_str2Index :=var_str2.first;
       var_str1Index := var_str1.next(var_str1Index);
    end loop;
  RETURN Result;
END strContain;

 --檢視2個字串是否匹配 包含:1 不包含:0(str1:aa,bb,cc str2: aa,bb)

相關文章