Source:
<code>public ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, List<AggregateNode> aggregateVector) throws StandardException { leftOperand = leftOperand.bindExpression(fromList, subqueryList, aggregateVector); rightOperand = rightOperand.bindExpression(fromList, subqueryList, aggregateVector); if( leftOperand.requiresTypeFromContext()) { leftOperand.setType(new DataTypeDescriptor(TypeId.getBuiltInTypeId(Types.VARCHAR), true)); leftOperand.setCollationUsingCompilationSchema(); } if( rightOperand.requiresTypeFromContext()) { rightOperand.setType(new DataTypeDescriptor(TypeId.getBuiltInTypeId(Types.VARCHAR), false)); rightOperand.setCollationUsingCompilationSchema(); } TypeId operandType = leftOperand.getTypeId(); int leftWidth = leftOperand.getTypeCompiler().getCastToCharWidth( leftOperand.getTypeServices()); if (leftWidth > Limits.DB2_LOB_MAXWIDTH / 2) { throw StandardException.newException(SQLState.BLOB_LENGTH_TOO_LONG, methodName, leftWidth * 2); } int width = leftWidth * 2; switch (operandType.getJDBCTypeId()) { case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: case Types.CLOB: break; case Types.JAVA_OBJECT: case Types.OTHER: { throw StandardException.newException(SQLState.LANG_UNARY_FUNCTION_BAD_TYPE, methodName, operandType.getSQLTypeName()); } default: DataTypeDescriptor dtd = DataTypeDescriptor.getBuiltInDataTypeDescriptor( <START> width>Limits.DB2_CHAR_MAXWIDTH?Types.CLOB:Types.VARCHAR, <END> true, width); leftOperand = (ValueNode) getNodeFactory().getNode( C_NodeTypes.CAST_NODE, leftOperand, dtd, getContextManager()); leftOperand.setCollationUsingCompilationSchema(); ((CastNode) leftOperand).bindCastNodeOnly(); operandType = leftOperand.getTypeId(); } setType(new DataTypeDescriptor( width>Limits.DB2_CHAR_MAXWIDTH?TypeId.getBuiltInTypeId(TypeId.CLOB_NAME):operandType, leftOperand.getTypeServices().isNullable(), width)); setCollationInfo(leftOperand.getTypeServices()); return this; }</code><technical_language>Code changes good. Limits.DB2_VARCHAR_MAXWIDTH instead of Limits.DB2_CHAR_MAXWIDTH</technical_language>

Target:
public ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, List<AggregateNode> aggregateVector) throws StandardException { leftOperand = leftOperand.bindExpression(fromList, subqueryList, aggregateVector); rightOperand = rightOperand.bindExpression(fromList, subqueryList, aggregateVector); if( leftOperand.requiresTypeFromContext()) { leftOperand.setType(new DataTypeDescriptor(TypeId.getBuiltInTypeId(Types.VARCHAR), true)); leftOperand.setCollationUsingCompilationSchema(); } if( rightOperand.requiresTypeFromContext()) { rightOperand.setType(new DataTypeDescriptor(TypeId.getBuiltInTypeId(Types.VARCHAR), false)); rightOperand.setCollationUsingCompilationSchema(); } TypeId operandType = leftOperand.getTypeId(); int leftWidth = leftOperand.getTypeCompiler().getCastToCharWidth( leftOperand.getTypeServices()); if (leftWidth > Limits.DB2_LOB_MAXWIDTH / 2) { throw StandardException.newException(SQLState.BLOB_LENGTH_TOO_LONG, methodName, leftWidth * 2); } int width = leftWidth * 2; switch (operandType.getJDBCTypeId()) { case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: case Types.CLOB: operandType = getResultType(width, operandType); break; case Types.JAVA_OBJECT: case Types.OTHER: { throw StandardException.newException(SQLState.LANG_UNARY_FUNCTION_BAD_TYPE, methodName, operandType.getSQLTypeName()); } default: operandType = getResultType(width, TypeId.getBuiltInTypeId(TypeId.VARCHAR_NAME)); DataTypeDescriptor dtd = DataTypeDescriptor.getBuiltInDataTypeDescriptor( operandType.getJDBCTypeId(), true, width); leftOperand = (ValueNode) getNodeFactory().getNode( C_NodeTypes.CAST_NODE, leftOperand, dtd, getContextManager()); leftOperand.setCollationUsingCompilationSchema(); ((CastNode) leftOperand).bindCastNodeOnly(); } setType(new DataTypeDescriptor( operandType, leftOperand.getTypeServices().isNullable(), width)); setCollationInfo(leftOperand.getTypeServices()); return this; }