简体   繁体   English

如何在sql(oracle)中不是null和not in语句?

[英]How to do both is not null and a not in statement in sql (oracle)?

I am trying to say the statement 我想说的是这句话

where date_end not in (null, 229)

I have already tried 我已经尝试过了

where date_end not in (229) and date_end is not null

I have also tried 我也试过了

where date_end is not null or date_end not (229)

This is necessary because I am using the date_end in a to_date statement to create a date. 因为我现在用的这是必要的date_endto_date语句来创建日期。 I want to ignore 229 because of leap years and nulls because it will not respond in the to_date statement. 我想忽略229因为闰年和空值,因为它不会在to_date语句中响应。

你可以试试:

where NVL(date_end, 229) != 229

You can simply write: 你可以简单地写:

where date_end <> 229

This also filters out NULL values. 这也会过滤掉NULL值。

The same is true for not in : not in也是如此:

where date_end not in (229)

If you want to be explicit, use and : 如果您想要明确,请使用and

where date_end <> 229 and date_end is not null

如果有其他非空值而不是229,这将是一个更好的选择。

(    where date_end is  null and  date_end  not in (229));

Just do: 做就是了:

where date_end not in ( 229 )

NULL NOT IN ( 229 ) always evaluates to NULL, which is equivalent to FALSE in WHERE clause. NULL NOT IN ( 229 )始终求值为NULL,这相当于WHERE子句中的FALSE。 Additional NOT NULL checking is needless. 额外的NOT NULL检查是不必要的。
Please examine a simple demo: http://www.sqlfiddle.com/#!4/358b6e/2 请查看一个简单的演示: http ://www.sqlfiddle.com/#!4/ 358b6e/2

CREATE table test(
  date_end int
);

INSERT ALL
INTO test VALUES( null )
INTO test VALUES( 229 )
INTO test VALUES( 123 )
SELECT null FROM dual;

SELECT * FROM test;

| DATE_END |
|----------|
|   (null) |
|      229 |
|      123 |

SELECT * FROM test
WHERE date_end NOT IN ( 229 )

| DATE_END |
|----------|
|      123 |

这对我有用,看看它是否适合你:

where date_end <>229 and date_end  is not null;

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

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