oracle function to achieve mysql find_set_in


Replace the FUNCTION or F_FIND_IN_SET Create (piv_str1 VARCHAR2, VARCHAR2 piv_str2, p_sep VARCHAR2: = ',')
the RETURN NUMBER the IS
  l_idx Number: = 0; - for calculating a position delimiter piv_str2
  str varchar2 (500); - The partition character substrings taken
  piv_str varchar2 (500): = piv_str2 ; - to assign piv_str2 piv_str
  RES Number: = 0; - returns the result
  res_place number: = 0; - position of the original string in the target string
the BEGIN
- if the field is null 0 returns
the IF THEN piv_str2 the iS nULL
  the rETURN RES;
the END the IF;
- if there is no delimiter piv_str, and direct determination piv_str1 piv_str are equal, are equal. 1 = res_place
the IF InStr (piv_str, p_sep,. 1 ) = 0 THEN
   the IF THEN piv_str = piv_str1
      res_place: =. 1;
      RES: = res_place;
   the END the IF;
the ELSE
 - cycle taken by the separator piv_str
LOOP
    l_idx: = InStr (piv_str, p_sep);
    -
    res_place: + = res_place. 1;
    - when there piv_str separator when
      the IF l_idx> 0 THEN
      - taken before the first delimiter field STR
         STR: = substr (piv_str,. 1,. 1-l_idx);
         - Analyzing and piv_str1 str are equal, the loop ends are equal determines
         the iF tHEN str = piv_str1
           RES: = res_place;
           the EXIT;
         the eND the iF;
        piv_str: = substr (piv_str, l_idx length + (p_sep));
      the ELSE
      - when delimiters after absence piv_str taken, it is determined whether the same piv_str and piv_str1 equal res_path = RES
        the iF THEN piv_str = piv_str1
           RES: = res_place;
        the END the iF;
        - equal regardless of whether the final We are out of the loop
        EXIT;
      The IF the END;
 the END LOOP;
 - end of the cycle
 the END the IF;
 - Returns RES
 the RETURN RES;
the END F_FIND_IN_SET;

Guess you like

Origin www.cnblogs.com/vofill/p/11803137.html