简体   繁体   English

SQL总是返回false

[英]SQL to always return false

I Want to write a sql query which will should always return false. 我想编写一个SQL查询,该查询应始终返回false。

if i write 如果我写

select 1 from dual where 1=2;

nothing is returned. 什么也不会返回。 how can i use where 1=2 which always returns "false". 我如何使用1 = 2总是返回“ false”的地方。

That's because there is nothing where 1 = 2. 那是因为1 = 2时没有任何东西。

select false from dual

(Substitute the value you want it to return for false.) (将您要返回的值替换为false。)

Based on the plsql and plsqldeveloper tags I have to believe you're using Oracle. 基于plsqlplsqldeveloper标签,我必须相信您正在使用Oracle。 As it turns out there is no BOOLEAN type in the Oracle database product, although a BOOLEAN type does exist in PL/SQL. 事实证明,尽管PL / SQL中确实存在BOOLEAN类型,但Oracle数据库产品中没有BOOLEAN类型。 When I find a need to include a "true or false" value in the database I'll create a CHAR(1) column and constrain it to contain only values of 'T' or 'F'; 当我发现需要在数据库中包含“ true or false”值时,我将创建一个CHAR(1)列并将其约束为仅包含“ T”或“ F”值; thus, if 'F' is acceptable as a "false" value you could do something like: 因此,如果将“ F”可接受为“假”值,则可以执行以下操作:

SELECT 'F' FROM DUAL

If you don't like 'F' you can substitute any value you'd care to choose for the 'F'. 如果您不喜欢“ F”,则可以用任何您愿意选择的值代替“ F”。

Share and enjoy. 分享并享受。

SELECT CASE WHEN 1=2 THEN 1 ELSE 0 END FROM DUAL

Why don't you simply use 你为什么不简单地使用

Select 1 选择1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM