Vivek wrote:
Hi,
Is it possible to insert a '\0' value or for that matter any control
character into a DB2 CHAR/VARCHAR field ? So if i do a 'select
hex(column) from table' i should see a 0 in the output. How can i do it
from the command prompt ?
Thanks,
Vivek
A bit of explanation:
Online documentation available at:
http://publib.boulder.ibm.com/infoce...w/v9/index.jsp
contains this (search for CHR in Version 8 incompatibilities):
http://publib.boulder.ibm.com/infoce...63%68%72%22%20
Output from CHR function
Change
CHR(0) returns a blank (X'20') instead of the character with code point X'00'.
Symptom
Output from the CHR function with X'00' as the argument returns different results.
Explanation
String handling when invoking and returning from user-defined functions
interprets X'00' as end of string.
Resolution
Change the application code to handle the new output value. Alternatively,
define a user-defined function that returns CHAR(1) FOR BIT DATA which is
sourced from the definition of the SYSFUN CHR function, and place this function
before SYSFUN on the SQL path.
For example, to find the source definition for SYSFUN.CHR located in column
IMPLEMENTATION:
SELECT IMPLEMENTATION, ROUTINENAME FROM SYSIBM.SYSROUTINES WHERE ROUTINENAME
LIKE '%CHR%';
IMPLEMENTATION ROUTINENAME
-------------- -----------
db2clifn!CLI_udfCHAR CHR
Then, you could create a new user-defined function from the definition
db2clifn!CLI_udfCHAR returned above.
CREATE FUNCTION DBS.CHR(INTEGER) RETURNS CHARACTER(1) FOR BIT DATA NOT FENCED
LANGUAGE C PARAMETER STYLE DB2SQL NO DBINFO EXTERNAL NAME db2clifn!CLI_udfCHAR'
You can also use Dmitri's suggestion of using x'00' instead of CHR(0)
Jan M. Nelken