CASE WHEN...INTO - 存储过程

发布于 2024-10-05 14:24:57 字数 318 浏览 2 评论 0原文

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

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

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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

反差帅 2024-10-12 14:24:57

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

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

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;
/
尽揽少女心 2024-10-12 14:24:57

不,但你可以这样做:

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;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文