show function status;
show create function get_spell;
mysql> show variables like '%func%';
+---------------------------------+-------+
| Variable_name | Value |
+---------------------------------+-------+
| log_bin_trust_function_creators | OFF |
+---------------------------------+-------+
set global log_bin_trust_function_creators=1;
-
delimiter $$
-
CREATE DEFINER=`root`@`%` FUNCTION `get_spell`(NAME VARCHAR(255) CHARSET gbk) RETURNS varchar(255) CHARSET gbk
-
BEGIN
-
DECLARE mycode INT;
-
DECLARE tmp_lcode VARCHAR(2) CHARSET gbk;
-
DECLARE lcode INT;
-
DECLARE tmp_rcode VARCHAR(2) CHARSET gbk;
-
DECLARE rcode INT;
-
DECLARE mypy VARCHAR(255) CHARSET gbk DEFAULT '';
-
DECLARE lp INT;
-
SET mycode = 0;
-
SET lp = 1;
-
SET NAME = HEX(NAME);
-
WHILE lp < LENGTH(NAME) DO
-
SET tmp_lcode = SUBSTRING(NAME, lp, 2);
-
SET lcode = CAST(ASCII(UNHEX(tmp_lcode)) AS UNSIGNED);
-
SET tmp_rcode = SUBSTRING(NAME, lp + 2, 2);
-
SET rcode = CAST(ASCII(UNHEX(tmp_rcode)) AS UNSIGNED);
-
IF lcode > 128 THEN
-
SET mycode =65536 - lcode * 256 - rcode ;
-
SELECT CONCAT(mypy,spell) INTO mypy FROM base_spell_code WHERE CODE >= ABS(mycode) ORDER BY CODE ASC LIMIT 1;
-
SET lp = lp + 4;
-
ELSE
-
SET mypy = CONCAT(mypy,CHAR(CAST(ASCII(UNHEX(SUBSTRING(NAME, lp, 2))) AS UNSIGNED)));
-
SET lp = lp + 2;
-
END IF;
-
END WHILE;
-
RETURN LOWER(mypy);
-
END $$
-
delimiter ;
参考:
http://my.oschina.net/u/1273696/blog/181995
http://blog.csdn.net/god123209/article/details/7577138
阅读(1496) | 评论(0) | 转发(0) |