1
我發現這個MySQL函數Base58編碼器在Github Gist中。PostgreSQL中的Base58編碼器函數
DELIMITER $$
CREATE FUNCTION base58_encode (num int) RETURNS varchar(255)
DETERMINISTIC
BEGIN
DECLARE alphabet varchar(255);
DECLARE base_count int DEFAULT 0;
DECLARE encoded varchar(255);
DECLARE divisor DECIMAL(10,4);
DECLARE mode int DEFAULT 0;
SET alphabet = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
SET base_count = CHAR_LENGTH(alphabet);
SET encoded = "";
WHILE num >= base_count DO
SET divisor = num/base_count;
SET mode = (num - (base_count* TRUNCATE(divisor,0)));
SET encoded = CONCAT(SUBSTRING(alphabet FROM mode+1 FOR 1), encoded);
SET num = TRUNCATE(divisor,0);
END WHILE;
SET encoded = CONCAT(SUBSTRING(alphabet FROM num+1 FOR 1), encoded);
RETURN (encoded);
END
我是的新手,難以將上面的函數轉換爲PostgreSQL函數。
對於Base58編碼器,上面的SQL代碼段的等效PostgreSQL
函數將如何工作?
你有什麼嘗試,哪裏有問題?因爲這應該是易於閱讀手冊 –
嗨@JuanCarlosOropeza,感謝提醒有關「手冊」。發佈PostgreSQL版本。 http://stackoverflow.com/a/34759277/1433665。謝謝! – TheKojuEffect