Re: Convert number into base 36 string
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 ;
Subject
Views
Written By
Posted
14673
March 21, 2006 11:22PM
3658
March 22, 2006 02:38PM
2941
June 23, 2006 12:10PM
Re: Convert number into base 36 string
5972
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.