Question

I'm writing a DB2 user-defined function for which I need an array of non-negative integers, which I represent as a varchar for bit data. I plan to use two bytes for each integer (giving me a maximum value of 2^16-1, which is acceptable).

I can convert an integer to a char for bit data by using the chr function, but how do I get it back to an integer?

Any additional advice on bit manipulation in DB2 procedures would be helpful as well, as I can't seem to find much documentation on it. I'm using v9.1 on Linux.

Was it helpful?

Solution

I'm not sure if CHR is actually what you want. According to the documentation, the CHR function:

Returns the character that has the ASCII code value specified by the argument. The argument can be either INTEGER or SMALLINT. The value of the argument should be between 0 and 255; otherwise, the return value is null.

The opposite of the CHR function is the ASCII function.

Full list of DB2 scalar procedures is here.

I'm not sure if writing a UDF in this way is the best for what you're trying to do. You may want to consider writing a stored procedure that's not in SQL. There's a list of supported languages, like Java, C, C++ etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top