2010-12-03 78 views
2

有沒有辦法在INTO語句中執行CASE?CASE WHEN ... 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; 
/
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

謝謝,我會嘗試。 – OneSneakyMofo 2010-12-03 06:20:15

+0

兩成條款不一個有效的查詢作出 – 2010-12-03 06:20:23