案例条款执行程序 [英] Case clause execution procedure

查看:102
本文介绍了案例条款执行程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的SQL非常慢.

select case when (value=1) 
then (select <Some Math Logic> from table where table.id=table_2.id) 
else 'false' end 
from table_2 where <where clause>

我想知道case子句如何工作.. ??

what i want to know is how does the case clause work..??

select <Some Math Logic> from table部分正在处理巨大的表集.

the part select <Some Math Logic> from table is working on huge table set.

在Java中,我们可以看到if语句

in Java we see that for an if statement

if(condition_1==true) 
{return output;} 
else 
{return false;}

如果if语句为false,则其中的部分将不会被处理,那么我想知道的是,它在oracle SQL中是否也相同.

if the if statement is false then the part inside it is never processed, then what i want to know is if it is the same in the oracle SQL also.

它在以下逻辑上工作吗??

does it work on the following logic..??

  • 检查案例条件
  • 如果为true,则在输出内部进行处理
  • 其他处理其他输出.

还是采用以下逻辑:

  • 预处理所有子查询
  • 检查案例条件
  • 如果为true,则在输出中显示
  • 其他显示其他输出.

请帮助

伙计们,我不想调整上面显示的查询...这只是一个假人.

edit: Guys i dont want to tune the query shown above... this is just a dummy one.

我需要知道的是case子句是如何逐步工作的.

what i need to know is how the case clause works step by step.

请分享是否有人为此输入

please share if any one has some input for that

推荐答案

似乎逻辑与Java中的逻辑完全一样.

It seems that the logic is exactly like that in java.

我使用以下逻辑来测试您的情况:

I used the following logic to test your scenario:

我创建了一个如下所示的伪函数,它将仅在dbms_output上写入内容,并且仅返回10.

I created a dummy function as below which will just write something on the dbms_output and return only 10.

CREATE OR REPLACE
  FUNCTION DISP_MSG
    RETURN VARCHAR2
  AS
    ret_val VARCHAR2(20):='10';
  BEGIN
    dbms_output.enable;
    dbms_output.put_line('executed');
    RETURN ret_val;
  END DISP_MSG;

然后我创建了一个匿名块来进行测试:

then i created an anonymous block to test the same:

DECLARE
  var VARCHAR2(100);
BEGIN
  SELECT CASE WHEN (1!=1) THEN DISP_MSG ELSE '1' END INTO var FROM dual;
  dbms_output.put_line('j = '||var);
END;

输出:

j = 1

j = 1

但是当我尝试以下操作时:

but when i tried the below:

DECLARE
  var VARCHAR2(100);
BEGIN
  SELECT CASE WHEN (1=1) THEN DISP_MSG ELSE '1' END INTO var FROM dual;
  dbms_output.put_line('j = '||var);
END;

输出:

已执行

j = 10

所以很清楚什么是执行逻辑

so its quite clear what is the execution logic

这篇关于案例条款执行程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆