MySQL Forums
Forum List  »  Stored Procedures

Re: Convert number into base 36 string
Posted by: Peter Brawley
Date: March 22, 2006 02:38PM

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;

Options: ReplyQuote


Subject
Views
Written By
Posted
14675
March 21, 2006 11:22PM
Re: Convert number into base 36 string
3658
March 22, 2006 02:38PM


Sorry, you can't reply to this topic. It has been closed.

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.