且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

DB2,当尝试计算提供的和存储的时间戳之间的差异时,我得到一个错误“函数的调用是荒谬的”

更新时间:2021-07-01 04:51:25

有几个重载版本的 DAYS()函数,接受不同数据类型的参数: DATE TIMESTAMP VARCHAR 。当您使用无类型参数标记( DAYS(?))时,查询编译器无法确定查询中要使用的函数的版本。

There are several overloaded versions of the DAYS() function, accepting parameters with different data types: DATE, TIMESTAMP, and VARCHAR. When you use an untyped parameter marker (DAYS(?)) the query compiler is unable to determine which version of the function to use in the query.

您可以明确指定参数数据类型进行编译: DAYS(CAST(?AS TIMESTAMP))。或者,如果您使用最近的DB2 for LUW版本(9.7及更高版本),则可以设置DB2注册表变量:

You can specify the parameter data type explicitly for compilation: DAYS(CAST(? AS TIMESTAMP)). Alternatively, if you are using a recent DB2 for LUW version (9.7 and higher) you can set the DB2 registry variable:

db2set DB2_DEFERRED_PREPARE_SEMANTICS=YES

告诉编译器它应该推迟PREPARE调用,直到查询执行时间参数数据类型是已知的。

to tell the compiler that it should defer the PREPARE call until the query execution time, when parameter data types are already known.