在plsql中检查for循环中的muliple字符串

时间:2018-07-05 15:32:36

标签: plsql

Oracle Plsql employee.code我需要检查多个位置,  如何在一处定义常量 并检查是否有循环返回值

 FOR employee IN( SELECT ep.employeeId,ep.code FROM employee e,           employeeDetail ep  WHERE ep.employeeId = e.employeeId )LOOP  

    if(i_empId  = employee.employeeId )then 

             if employee .code IN ('641','642','6','404','5','6','7','8','9','','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','430','31','32','33','34','35','36','37','38','4439','40','41','42','43','44','45','46','47','48','49','50','51','52','53','54','55','56','57','58','59','60','61','62','63','64','65','66','67','68','69','70','71','72','73','74','75','76','77','78','79','80','81','82','83','84','85','86','87','88','89','90','91','92','93','94','95','96','97','98','99')) then 
                       isfRequiredon := 'Y';
                        end if;
                       end if;
                    end loop

2 个答案:

答案 0 :(得分:0)

您可以像这样使用PL / SQL集合和member of运算符:

declare
   type vc_tab_type is table of varchar2(10);
   vc_tab vc_tab_type := vc_tab_type('641','642','6','404','5','6','7','8','9','','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','430','31','32','33','34','35','36','37','38','4439','40','41','42','43','44','45','46','47','48','49','50','51','52','53','54','55','56','57','58','59','60','61','62','63','64','65','66','67','68','69','70','71','72','73','74','75','76','77','78','79','80','81','82','83','84','85','86','87','88','89','90','91','92','93','94','95','96','97','98','99');
begin
   FOR employee IN( SELECT ep.employeeId,ep.code FROM employee e, 
                           employeeDetail ep  WHERE ep.employeeId = e.employeeId )LOOP  
      if(i_empId  = employee.employeeId )then 
         if employee.code member of vc_tab  then
            isfRequiredon := 'Y';
         end if;
      end if;
   end loop;
end;  

答案 1 :(得分:0)

declare
  v_code_check BOOLEAN := false;
  vc_tab       varchar2(2000) :=   ('641,642,6,404,5,6,7,8,9,,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,430,31,32,33,34,35,36,37,38,4439,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99');
begin
  FOR employee IN (SELECT ep.employeeId, ep.code
                     FROM employee e, employeeDetail ep
                    WHERE ep.employeeId = e.employeeId) LOOP
    if (i_empId = employee.employeeId) then
      IF INSTR(vc_tab, employee.employeeId) > 0 THEN
        v_code_check := TRUE;
      ELSE
        v_code_check := FALSE;
      END IF;
      if (v_code_check) then
        isfRequiredon := 'Y';
      end if;
    end if;
  end if;
end loop;
end;