SQL SQLite 选择哪里为空?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3620828/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQLite select where empty?
提问by Timo Huovinen
In SQLite, how can I select records where some_column is empty?
Empty counts as both NULL and "".
在 SQLite 中,如何选择 some_column 为空的记录?
Empty 算作 NULL 和 ""。
回答by Guffa
There are several ways, like:
有几种方法,例如:
where some_column is null or some_column = ''
or
或者
where ifnull(some_column, '') = ''
or
或者
where coalesce(some_column, '') = ''
of
的
where ifnull(length(some_column), 0) = 0
回答by Daniel Vassallo
It looks like you can simply do:
看起来你可以简单地做:
SELECT * FROM your_table WHERE some_column IS NULL OR some_column = '';
Test case:
测试用例:
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);
Result:
结果:
SELECT id FROM your_table WHERE some_column IS NULL OR some_column = '';
id
----------
1
2
5
回答by μBio
Maybe you mean
也许你的意思是
select x
from some_table
where some_column is null or some_column = ''
but I can't tell since you didn't really ask a question.
但我不能说,因为你并没有真正提出问题。
回答by mahesh takkalwad
You can do this with the following:
您可以使用以下方法执行此操作:
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);
This will give you the no of rows where the column value is null or blank.
这将为您提供列值为空或空白的行数。