字符串数据右截断DB2错误

时间:2016-12-21 17:11:32

标签: sql db2 truncate

我收到错误"字符串数据右截断"在我使用此查询时在db2上

SELECT BILL_NUMBER, 'PAPERWORK BUT NOT COMPLETE', 'NONE', NULL, '00000',NULL,NULL,TOTAL_CHARGES, NULL FROM TLORDER WHERE 
CURRENT_STATUS NOT IN ('COMPLETE','APPRVD','PAPERWISE','BILLD','EDIBILLED','CANCL')   AND BILL_TO_CODE NOT LIKE CASE WHEN :INCLUDE_DED = 'No' THEN 'ROCD%' ELSE '1234kkh5656' END
AND EXISTS (SELECT 1 FROM LIST_CHECKIN_AUDIT A WHERE A.BILL_NUMBER = TLORDER.BILL_NUMBER FETCH FIRST 1 ROW ONLY)
AND SITE_ID = :SITE AND DELIVER_BY_END >= CURRENT TIMESTAMP - 3 MONTHS AND COALESCE(PICK_UP_DRIVER,'') = '' AND '00000' =:DRIVER_ID 

然而,当我压制这一行时,我没有得到错误。

AND BILL_TO_CODE NOT LIKE CASE WHEN :INCLUDE_DED = 'No' THEN 'ROCD%' ELSE '1234kkh5656' END

提前致谢!

2 个答案:

答案 0 :(得分:2)

我冒昧地猜测,当:INCLUDE_DED主机变量的值超过2个字节时会发生这种情况。您不提供变量数据类型,因此查询编译器从比较的右侧派生它,其中文字'No'的长度为2个字节。如果您随后为主变量分配了类似'Yes'的值,则必须将其截断。

考虑向主机变量引用添加显式类型信息,例如:

...WHEN CAST(:INCLUDE_DED AS VARCHAR(10)) = 'No'...

使用适合可能值范围的数据类型。

答案 1 :(得分:0)

我首先检查bill_to_code的数据类型。您将返回可能超出数据类型长度的“1234kkh5656”。