1

I am tring to perform a BITOR on a argument that i am passing into a function. so i wrote the below code. Statement 'SET result = arg1 | arg2 ' isnt working. I tried few ways, however i wasnt able to achieve the right result. What do i need to change ?

DELIMITER $$
CREATE FUNCTION BIT_OR(arg1 varchar(255),arg2 varchar(255)) RETURNS varchar(255)
BEGIN
DECLARE result varchar(255);
BEGIN
SET result = arg1 | arg2;
END;
RETURN result;
END $$
DELIMITER ;

select bitwise_OR(00011101,00001111);  -- 12127 ( i am expecting 00011111 or 31 (decimal equivalent))
Oggu
  • 323
  • 1
  • 6
  • 18
  • Try: `SET result := CONV(arg1, 2, 10) | CONV(arg2, 2, 10); -- 31 (DEC)`. – wchiquito May 20 '16 at 15:02
  • You can, of course, just `SELECT b'00011101' | b'00001111';` but if you're going to do it your way, you need to quote those strings when calling the function and use `CONV()` as @wchiquito points out, because as it is now, those are being handled as base 10 signed integers, implicitly cast to varchar, then implicitly cast back to base 10 integers, then or'ed together. Yow. – Michael - sqlbot May 21 '16 at 00:33

0 Answers0