oracle sql - 如何获取包含string或null的列

时间:2016-05-04 14:27:52

标签: sql oracle

我有3列的表格:

enter image description here

我想获取所有记录where type like '%' and is_connect like 'N',包括类型IS NULL或包含字符串的行。

我的查询:

SELECT * 
FROM OFFER 
WHERE TYPE LIKE '%' 
AND IS_CONNECT LIKE 'N';

我得到了类型为NOT NULL的行,但是如何获取所有行,即使类型为IS NULL

4 个答案:

答案 0 :(得分:1)

如果您想要获取值或没有值的所有行或行,只需从where子句中排除该字段:

SELECT * FROM OFFER WHERE IS_CONNECT = 'N';

答案 1 :(得分:1)

如果您想要所有类型的条目,请删除like子句:

SELECT * FROM OFFER WHERE (TYPE LIKE '%'  or TYPE is NULL) AND IS_CONNECT = 'N';

答案 2 :(得分:1)

试试这个。

Where N is you first alphabet. 
SELECT * FROM OFFER 
WHERE TYPE is null 
AND IS_CONNECT LIKE 'N%';

Where N is the last alphabet in your type. 
SELECT * FROM OFFER 
WHERE TYPE is null 
AND IS_CONNECT LIKE '%N';

__ BCG14

答案 3 :(得分:0)

你几乎就在那里。只需要使用OR条件来包括空检查...而且,你没有' N%'在is_connect之后

SELECT * FROM OFFER WHERE (TYPE LIKE '%'  or TYPE is NULL) AND IS_CONNECT LIKE 'N%'