在sqlite中,如何选择some_column为空的记录?
空算作零和“”。

有帮助吗?

解决方案

有几种方法,例如:

where some_column is null or some_column = ''

或者

where ifnull(some_column, '') = ''

或者

where coalesce(some_column, '') = ''

where ifnull(length(some_column), 0) = 0

其他提示

看起来您可以简单地做:

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    

也许你是说

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

但是我不能说,因为您并没有真正问一个问题。

您可以使用以下操作:

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或空白的无行。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top