MySQL Forums
Forum List  »  Stored Procedures

Re: Convert number into base 36 string
Posted by: Barry Gould
Date: June 23, 2006 11:10AM

There are some problems with the above.

Here is a function that works:


DELIMITER $$

DROP FUNCTION IF EXISTS `classifieds`.`PRINTBASE` $$
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
SET res = num % base;
SET num = num DIV base;
SET stream = CONCAT(MID( chars, res + 1, 1 ), stream);
END WHILE;
RETURN stream;

END $$

DELIMITER ;

Options: ReplyQuote


Subject
Views
Written By
Posted
12193
March 21, 2006 11:22PM
Re: Convert number into base 36 string
4177
June 23, 2006 11:10AM


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.