Oracle 은 쉼표 로 구 분 된 문자열 에 따라 구 덩이 를 동시에 기록 합 니 다.

보고 서 는 필요 하지 않 은 데 이 터 를 걸 러 내야 합 니 다. 보고 서 는 부품 번호 에 따라 통계 되 기 때문에 격 에 맞지 않 는 제품 을 걸 러 내야 합 니 다. 관련 된 재료 코드 (부품 번호) 에 따라 걸 러 야 합 니 다. not in 을 통 해 걸 러 낼 수 밖 에 없 지만 천진 한 저 는 아래 코드 로 조 회 를 합 니 다.
b.part_no not in (select  replace(wm_concat(t.materielcode),',',''',''') from quality_check t where t.materielcode is not null)

아무리 해도 걸 러 지지 않 습 니 다. 이것 은 IN 이후 문자열 이 아니 라 결과 집합 이기 때 문 입 니 다. 위의 스 크 립 트 에서 찾 아 낸 결 과 는 첫 번 째 입 니 다.
    
   :
001,002,003,004 

   :
001
002
003
004

그래서 위의 조회 결 과 를 구분 해 야 합 니 다.
1. 반환 대상 데이터 형식 만 들 기:
create or replace type mytype as table of varchar2(4000) 

숫자 로 도 가능 합 니 다.
create or replace type mytype as table of number;

2. 분리 함수 만 들 기
create function my_split(piv_str in varchar2, piv_delimiter in varchar2)  
  --piv_str     ,piv_delimiter       
  return mytype is  
  j        int := 0;  
  i        int := 1;  
  len      int := 0;  
  len1     int := 0;  
  str      varchar2(4000);  
  my_split mytype := mytype();  
begin  
  len  := length(piv_str);  
  len1 := length(piv_delimiter);  
  while j < len loop  
    j := instr(piv_str, piv_delimiter, i);  
    if j = 0 then  
      j   := len;  
      str := substr(piv_str, i);  
      my_split.extend;  
      my_split(my_split.count) := str;  
      if i >= len then  
        exit;  
      end if;  
    else  
      str := substr(piv_str, i, j - i);  
      i   := j + len1;  
      my_split.extend;  
      my_split(my_split.count) := str;  
    end if;  
  end loop;  
  return my_split;  
end my_split;  

3. sql 완성:
select *
  from manu_taskinfo mt
 where mt.part_no not in
       (select column_value
          from table (select my_split(wm_concat(t.materielcode), ',')
                        from quality_check t
                       where t.materielcode is not null))

  
다음으로 전송:https://www.cnblogs.com/echo-ling/p/7479308.html

좋은 웹페이지 즐겨찾기