SQLiteselect哪里空?
在SQLite中,如何selectsome_column为空的logging?
空作为NULL和“”计数。
有几种方法,如:
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 = '';
testing用例:
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);
这会给你列值为空或空白的行号。