SQLite select where empty?

后端 未结 4 483
春和景丽
春和景丽 2021-01-29 23:33

In SQLite, how can I select records where some_column is empty?
Empty counts as both NULL and \"\".

相关标签:
4条回答
  • 2021-01-29 23:51

    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.

    0 讨论(0)
  • 2021-01-29 23:58

    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.

    0 讨论(0)
  • 2021-01-29 23:59

    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    
    
    0 讨论(0)
  • 2021-01-30 00:03

    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
    
    0 讨论(0)
提交回复
热议问题