今天的(教育)测验 [英] (educating) Quiz for today

查看:55
本文介绍了今天的(教育)测验的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这篇文章很可能是由于过多的业余时间:)但是,如果您对SQL感兴趣,那么您可能会发现这很引人注目.我发现这个问题很有趣(如果您不了解预定义的条件或条件成本,则会有些困惑).

如果考虑在SQL中将条件与OR组合的评估顺序.此语句的正确评估顺序是什么,它会失败吗?

Most likely this post is because of too much spare time :) But if you''re interested in SQL you may find this compelling. I find this issue amusing (and a bit confusing if you don''t know about pre-defined conditions or condition cost).

If you think about the evaluation order of conditions combined with OR in SQL. What is the correct evaluation order for this statement, does it fail?

SELECT 1
WHERE 1/0=42 OR 1=1


随时更改顺序并测试结果(在您喜欢的DBMS中).

那一个(为Sql Server写的)呢?


Feel free to change the order and test the results (in your favorite DBMS).

What about this one (written for Sql Server):

SELECT 1
WHERE 1/(SELECT COUNT(*) FROM sysobjects WHERE type = 'NotPossible')=2 OR 2<5


在不同的数据库之间,此行为将有所不同.


The behavior will be a bit different among different databases.

推荐答案

我只是在Oracle 9.2.0.5上运行它,它始终返回1.:)
I just ran it on Oracle 9.2.0.5 and it always returns 1. :)
SQL> select 1 from dual where 1/0=42 or 1=1;
         1
----------
         1
SQL> edit
Wrote file afiedt.buf
  1  select 1 from dual
  2*  where 1=1 or 1/0=42
  3  ;
         1
----------
         1
SQL> edit
Wrote file afiedt.buf
  1  select 1 from dual
  2*  where 1=1 or 1/(select count(*) from all_tables where table_name = ''NOTHING'')=42
  3  ;
         1
----------
         1
SQL> edit
Wrote file afiedt.buf
  1  select 1 from dual
  2*  where 1/(select count(*) from all_tables where table_name = ''NOTHING'')=42 or 1=1
  3  ;
         1
----------
         1
SQL> 


我希望这并不意味着Oracle是卓越的,或者是例外. :)


I hope this doesn''t mean that Oracle is exceptional or rather exceptionless. :)


这篇关于今天的(教育)测验的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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