방법

2009-02-28 5 views
0

은 내가 어떻게 예를 들어 쿼리
를 사용하여 동일한 절차 내에서 프로 시저 매개 변수에 액세스 할 쿼리에서 프로 시저 매개 변수를 사용하는 방법 : 위의 절차에서와 병합 문에이 절차방법

procedure game(left in tab.left%type,right in tab.right%type,...) 
is 
--some local variables 
begin 
merge into tgt_table 
using subquery --(here is what i need to use the parameters) 
on some condition 
when matched then 
update the tgt table 
when not matched then 
insert the table; 
end game; 

를 참조, 난 매개 변수 값을 테이블 참조로 사용하고 주어진 조건에 따라 테이블에 업데이트하거나 삽입하는 값을 사용하는 쿼리가 필요합니다.

도와주세요.

답변

1

당신은 당신의 매개 변수를 사용하여 테이블을 정의 할 경우 동적 SQL을 사용해야합니다 읽어 보시기 바랍니다 미리 감사드립니다 - 무언가 같이 그러나

procedure game(left in tab.left%type,right in tab.right%type,...) 
is 
    --some local variables 
    l_sql long; 
begin 
    l_sql := 'merge into tgt_table' 
      || ' using ' || left 
      || ' on some condition' 
      || ' when matched then' 
      || ' update ' || right 
      || ' when not matched then' 
      || ' insert the table'; 
    execute immediate l_sql; 
end game; 

, 당신은 더 많은 일을 왼쪽이 do, condition, update 및 insert 절이 모두 사용되는 테이블에 따라 변경되어야하기 때문입니다. 나는이 조달이 특히 유용 할 것이라고 확신하지 못한다.