Re: Convert number into base 36 string
You forgot to divide, eg...
CREATE FUNCTION PRINTBASE( num BIGINT, base SMALLINT )
RETURNS VARCHAR(255)
DETERMINISTIC
BEGIN
DECLARE chars CHAR(36) DEFAULT "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
DECLARE stream CHAR(32) DEFAULT "";
DECLARE res INT;
WHILE num > 0 DO
IF num < 36 THEN
SET res = num;
SET num = 0;
ELSE
SET res = num / base;
SET num = num % base;
END IF;
SET stream = CONCAT( stream, MID( chars, res, 1 ));
END WHILE;
RETURN stream;
END;
Subject
Views
Written By
Posted
15346
March 21, 2006 11:22PM
Re: Convert number into base 36 string
3833
March 22, 2006 02:38PM
3094
June 23, 2006 12:10PM
6271
June 23, 2006 11:10AM
Sorry, you can't reply to this topic. It has been closed.
This forum is currently read only. You can not log in or make any changes. This is a temporary situation.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.