134

在 SQLite 中,如何选择some_column空的记录?
空算作NULL""

4

4 回答 4

306

有几种方法,例如:

where some_column is null or some_column = ''

或者

where ifnull(some_column, '') = ''

或者

where coalesce(some_column, '') = ''

where ifnull(length(some_column), 0) = 0
于 2010-09-01T18:06:49.497 回答
28

看起来你可以简单地做:

SELECT * FROM your_table WHERE some_column IS NULL OR some_column = '';

测试用例:

CREATE TABLE your_table (id int, some_column varchar(10));

INSERT INTO your_table VALUES (1, NULL);
INSERT INTO your_table VALUES (2, '');
INSERT INTO your_table VALUES (3, 'test');
INSERT INTO your_table VALUES (4, 'another test');
INSERT INTO your_table VALUES (5, NULL);

结果:

SELECT id FROM your_table WHERE some_column IS NULL OR some_column = '';

id        
----------
1         
2         
5    
于 2010-09-01T18:03:41.920 回答
1

也许你的意思是

select x
from some_table
where some_column is null or some_column = ''

但我不能说,因为你并没有真正问过问题。

于 2010-09-01T18:04:17.507 回答
0

您可以使用以下方法执行此操作:

int counter = 0;
String sql = "SELECT projectName,Owner " + "FROM Project WHERE Owner= ?";
PreparedStatement prep = conn.prepareStatement(sql);
prep.setString(1, "");
ResultSet rs = prep.executeQuery();
while (rs.next()) {
    counter++;
}
System.out.println(counter);

这将为您提供列值为空或空白的行数。

于 2017-08-29T07:15:51.823 回答