Skip navigation links

MySQL Forums :: Stored Procedures :: Convert number into base 36 string


Advanced Search

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
Convert number into base 36 string 10112 Benoit St-Jean 03/21/2006 11:22PM
Re: Convert number into base 36 string 2628 Peter Brawley 03/22/2006 02:38PM
Re: Convert number into base 36 string 2239 Peter Brawley 06/23/2006 12:10PM
Re: Convert number into base 36 string 3237 Barry Gould 06/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.