在SQLite中,如何选择some_column为空的记录? Empty计为NULL和“”。
答案 0 :(得分:272)
有几种方法,例如:
where some_column is null or some_column = ''
或
where ifnull(some_column, '') = ''
或
where coalesce(some_column, '') = ''
的
where ifnull(length(some_column), 0) = 0
答案 1 :(得分:25)
看起来你可以做到:
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
答案 2 :(得分:1)
也许你的意思是
select x
from some_table
where some_column is null or some_column = ''
但我不知道,因为你没有真正提出问题。
答案 3 :(得分: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);
这将为您提供列值为null或空白的行数。