相当于ISNULL(),NVL(),IFNULL()或COALESCE SQLite的()NVL、ISNULL、IFNULL、SQLite

2023-09-02 01:40:24 作者:詭異……氣氛

我想,以避免许多检查就像在我code以下内容:

I'd like to avoid having many checks like the following in my code:

myObj.someStringField = rdr.IsDBNull(someOrdinal) 
                            ? string.Empty 
                            : rdr.GetString(someOrdinal);

我想我可以有我的查询,照顾空的做这样的事情:

I figured I could just have my query take care of the nulls by doing something like this:

SELECT myField1, [isnull](myField1, '') 
FROM myTable1
WHERE myField1 = someCondition

我使用SQLite的,虽然,它似乎并没有认识到 ISNULL 功能。我也试过在其他数据库(公认的一些等同的 NVL() IFNULL() COALESCE()),但SQLite的似乎不认识任何人。

I'm using SQLite though and it doesn't seem to recognize the isnull function. I've also tried some equivalent ones recognized in other databases (NVL(), IFNULL() and COALESCE()), but SQLite doesn't seem to recognize any of them.

没有人有任何建议或知道的更好的方法来做到这一点。不幸的是数据库没有所有字段的默认值。另外,我需要使用一些 LEFT JOIN在某些情况下,一些返回的字段将是空的,因为在左边的匹配记录JOIN 条款表将不存在。

Does anyone have any suggestions or know of a better way to do this. Unfortunately the database doesn't have default values for all fields. Plus, I need to use some LEFT JOIN clauses in some cases, where some of the fields returned will be null because the matching record in the LEFT JOIN table will not exist.

推荐答案

IFNULL ,在这里看到:http://www.sqlite.org/lang_corefunc.html#ifnull

没有括号功能