Oracle is only 1-7 weeks to check the numbers can not be repeated

1, the use of Oracle REGEXP_INSTR matching numbers

select REGEXP_INSTR ('1357', '^[1-7]{1,7}$') into n_Count from dual;
View Code

2, look for duplicate circulation figures

    for i in 1..length(i_vc_Week) loop
        v_findStr:=substr(i_vc_Week,i,1);
        if nvl(instr(i_vc_Week,v_findStr,(i+1)),0)>0 then
          return 2;
        end if;
     end loop;
View Code

Complete Method

  FUNCTION P_SR_CheckWeekLegal(i_vc_Week varchar2)
  return integer
  IS
     n_Count integer;
     v_findStr varchar2(1);
  BEGIN
     n_Count:=0;
     select REGEXP_INSTR (i_vc_Week, '^[1-7]{1,7}$') into n_Count from dual;
     if n_Count=0 then
       return 2;
     end if;
     for i in 1..length(i_vc_Week) loop
        v_findStr:=substr(i_vc_Week,i,1);
        if nvl(instr(i_vc_Week,v_findStr,(i+1)),0)>0 then
          return 2;
        end if;
     end loop;
         return n_Count;
    END;
View Code

 

Reference https://docs.oracle.com/database/121/SQLRF/functions162.htm#SQLRF06300

Guess you like

Origin www.cnblogs.com/ZJ199012/p/11935014.html