2010-12-03 5 views
2

사례 CASE WHEN INTO 문을 수행하는 방법은 무엇입니까?사례 ... INTO - 저장 프로 시저

Create or replace procedure example 
AS 
Variable1 varchar; 
Variable2 varchar; 

BEGIN 
    Select (CASE WHEN number = 1 THEN 
       This_thing INTO Variable1 
      ELSE 
       That_thing INTO Variable2) The_Other 
    FROM table; 
END; 

답변

5

우리는 하나의 CASE() 문에서 두 개의 출력을 얻을 수 없습니다. 최상의 조건은 서로 배타적 인 조건으로 두 번의 전화가 걸려 오는 것입니다.

create or replace procedure example as 

    variable1 t69.this_thing%type; 
    variable2 t69.that_thing%type; 

begin 
    select (case when whatever = 1 then 
       this_thing 
      else 
       null 
      end) 
     , (case when whatever != 1 then 
       that_thing 
      else 
       null 
      end) 
    into variable1, variable2   
    from t69; 
end; 
/
+0

에서 복사 –

+0

이 무엇이든 = 1로 대체 whould 원래 쿼리 –

2

아니,하지만 당신이 그렇게 할 수 있습니다

declare 
Variable1 varchar2(30); 
Variable2 varchar2(30); 
BEGIN 
    Select decode(dummy,'X','This_thing'), 
      decode(dummy,'X',null,'That_thing') 
    INTO Variable1,Variable2 
    FROM dual; 
END; 
+0

감사합니다. 조항 INTO – OneSneakyMofo

+0

두가 유효한 쿼리 –

+0

OMG 조랑말을하지 않습니다, 그래 고정, 내가 잘못 (때 어떤! = 1 다음 널 다른 that_thing 최종 경우) –