1

I am using a decode function in Informix database. I am retrieving a field which is an integer datatype. If the value I retrieved is '' then I need to set it as null; if not I am setting the same value.

I tried like this:

decode(table1.field1,'',NULL,table1.field1)

but I am getting the following error

Corresponding types must be compatible in CASE expression.

I am confused how the value will be retrieved from database — as null or as 0 or -1 or something. Do I need to do like this?

decode(table1.field1,'',0,table1.field1)

how to resolve it

4

1 回答 1

3

这里有些混乱。由于table1.field1它是一个 INTEGER 列,因此它永远不会包含空字符串。它将包含 NULL 或有效的 INTEGER 值;所以根本不需要更新。

为什么你认为你可能会得到''?如果您的编程语言区分类型,您必须将 INTEGER 列选择为字符串变量。否则,空字符串很可能是您的编程语言表示空值的方式。

于 2012-10-12T17:47:56.163 回答