oracle CASE WHEN...INTO - 存储过程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4342942/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 22:06:28  来源:igfitidea点击:

CASE WHEN...INTO - Stored Procedure

sqloraclestored-proceduresplsqlcase

提问by OneSneakyMofo

is there any way to do a CASE WHEN INTO Statement?

有什么办法可以做一个 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;

回答by APC

We cannot get two outputs from a single CASE() statement. The best you can achieve is having two separate calls with mutually exclusive conditions:

我们无法从单个 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;
/

回答by xt.and.r

No, but you can so:

不,但你可以这样做:

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;