2

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.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

ASCII is exactly the function I needed. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.