我不确定这种情况是否仅与 Coldfusion 或 Mysql 有关。
如果将 TEXT 类型的列与不相等的空字符串值进行比较,则此代码有效:
column > ""
但不是这个:
column != ""
在我的 SQL 代码中,假设具有 TEXT 类型的数据库列附件中包含字符串。输入附件( :attachment )的 Form 值为空(我认为它将引用"")。
attachment = (
CASE
WHEN :attachment = "" AND attachment = ""
THEN 1
WHEN :attachment = "" AND attachment != ""
THEN 2
WHEN :attachment != "" AND attachment = ""
THEN 3
WHEN :attachment != "" AND attachment != ""
THEN 4
ELSE attachment
END
)
此代码将返回附件 = 3。
但是,如果我使用这个 SQL 代码:
attachment = (
CASE
WHEN :attachment = "" AND attachment = ""
THEN 1
WHEN :attachment = "" AND attachment > ""
THEN 2
WHEN :attachment > "" AND attachment = ""
THEN 3
WHEN :attachment > "" AND attachment > ""
THEN 4
ELSE attachment
END
)
此代码返回附件 = 2,这是我真正期望的。
那么,比较列是否相等或不等于空字符串的最佳方法是什么?我很少使用 NULL 值,因为当保存 FORM 时,它们会输入空字符串。