用户自定义函数(UDF)的问题,关于返回值
Ewer 2003-03-07 05:16:35 以下摘自db2帮助文档: 关于UDF和DB2之间接口的char类型的数据
• For a CHAR(n) parameter, DB2 always moves n bytes of data to the buffer and sets the n+1 byte to null. For a RETURNS CHAR(n) value, DB2 always takes the n bytes and ignores the n+1 byte. For this RETURNS CHAR(n) case, you are warned against the inadvertent inclusion of a null-character in the first n characters. DB2 will not recognize this as anything but a normal part of the data, and it might later on cause seemingly anomalous results if it was not intended.
根据上面的一些话,看看喽,就是返回值中有’\0’的问题.现在我程序的返回值中是返回的一个”1979-01-01”其中在最后是有’\0’的。
如果我在create function中写的是返回 return char(11),根据上面的e文的意思是需要在前11字符中包含一个’\0’。这样做的结果:在命令行状态察看表信息是正确的”1979-01-01”,而在图形界面的控制中心界面下,显示的是”1979-01-01□”,我的理解是最后那个方框是’\0’。
如果我在create function 写的是 return char(10)的话,在两种显示情况下描述的都是正确的结果:”1979-01-01”,没有哪个方框。
所以对于写10和11我不是很明白应该选哪种写法,以及这样处理之后,对后面的处理各有什么影响。