2014-12-22 8 views
2

필자는 PL/SQL에서 콜렉션을 가진 초보자이며, BULK COLLECTFORALL다중 테이블 레코드의 테이블로 사용하려고합니다. 루프를 반복하는 방법은 무엇입니까?이 여러 열의 테이블을 반복하는 방법은 무엇입니까?

다른 구문 옵션을 시도했지만 모두 실패했습니다. 복수 열에 대한 온라인 참조를 찾을 수 없습니다. 단일 열으로 예제를 찾을 수 있습니다.

--Here are my declarations. Note that there is more than one column in the record. 
--The examples I could find online only use one column: 
type mytable_rec is record 
(
     mytable_col1 mytable.mytable_col1%type, 
     mytable_col2 mytable.mytable_col2%type 
); 

type mytable_tab is table of mytable_rec; 

l_mytable mytable_tab ; 

--I've already loaded my query into l_mytable using bulk collect. 
--Skipping it for readability 

forall i in 1 .. l_mytable.count loop --The procedure won't compile 
             --because of this line 
     update mytable set 
      mytable.mytable_col1 = i.mytable_col1, 
      mytable.mytable_col2 = i.mytable_col2 
     where 1 = 1; --some condition goes here        
end loop;  

중 하나가 작동하지 않습니다 다음을 시도 :

forall i in l_mytable.first .. l_mytable.last loop --The procedure won't compile 
                --because of this line 
     update mytable set 
      mytable.mytable_col1 = i.mytable_col1, 
      mytable.mytable_col2 = i.mytable_col2 
     where 1 = 1; --some condition goes here        
end loop; 

감사합니다!/:

+1

에서 더 많은 정보를 찾을 수 below.please 시도 /www.oracle.com/technetwork/issue-archive/2012/12-sep/o52plsql-1709862.html) –

+0

@smn_onrocks 답장을 보내 주셔서 감사합니다. 불행히도이 예제는 또한 단일 열을 사용합니다. 내 테이블이 여러 열을 포함하는 레코드의 테이블 인 경우이를 통해 반복 할 수 있습니까? – Zesty

답변

1

친절하게 내가이 유뿐만 아니라 그것을 [링크] (HTTP를 할 수있는 프로세스를 구현을 이해하는 데 도움이 될 것입니다 생각 링크를 시도이 링크 FORALL Update - Updating multiple columns

forall i in l_mytable.first .. l_mytable.last --The procedure won't compile 
               --because of this line 
    update mytable set 
     mytable.mytable_col1 = l_mytable.mytable_col1(i), 
     mytable.mytable_col2 = l_mytable.mytable_col2(i) 
    where 1 = 1; --some condition goes here        
+0

답장을 보내 주셔서 감사합니다. 동일한 줄에서 계속 실패합니다 (l_mytable.first .. l_mytable.last 루프에서 forall입니다.) : [오류] 구문 검사 (2444 : 47) : 발견 : '루프'예상 : DELETE EXECUTE INSERT MERGE UPDATE - 또는 - SAVE - 또는 - + - || - 또는 - */MOD REMAINDER - 또는 - ** - 또는 - (+) 일일 멀티 세트 년 또는 - %. [-or- (OVER -or-- @ – Zesty

+1

for 루프는 루프 키워드 – psaraj12

+0

을 필요로하지 않습니다. 고마워요.하지만 인덱스는 테이블 옆에 있습니다. 예를 들어 l_mytable (i) .mytable_col1 – Zesty

관련 문제