Chinaunix首页 | 论坛 | 博客
  • 博客访问: 437425
  • 博文数量: 126
  • 博客积分: 35
  • 博客等级: 民兵
  • 技术积分: 1262
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-19 16:39
文章分类

全部博文(126)

文章存档

2017年(2)

2016年(20)

2015年(64)

2014年(24)

2013年(16)

我的朋友

分类: Mysql/postgreSQL

2016-01-28 10:47:08

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; 


点击(此处)折叠或打开

  1. delimiter $$
  2. CREATE DEFINER=`root`@`%` FUNCTION `get_spell`(NAME VARCHAR(255) CHARSET gbk) RETURNS varchar(255) CHARSET gbk
  3. BEGIN
  4.     DECLARE mycode INT;
  5.     DECLARE tmp_lcode VARCHAR(2) CHARSET gbk;
  6.     DECLARE lcode INT;
  7.      DECLARE tmp_rcode VARCHAR(2) CHARSET gbk;
  8.     DECLARE rcode INT;
  9.      DECLARE mypy VARCHAR(255) CHARSET gbk DEFAULT '';
  10.     DECLARE lp INT;
  11.      SET mycode = 0;
  12.     SET lp = 1;
  13.      SET NAME = HEX(NAME);
  14.      WHILE lp < LENGTH(NAME) DO
  15.          SET tmp_lcode = SUBSTRING(NAME, lp, 2);
  16.         SET lcode = CAST(ASCII(UNHEX(tmp_lcode)) AS UNSIGNED);
  17.         SET tmp_rcode = SUBSTRING(NAME, lp + 2, 2);
  18.         SET rcode = CAST(ASCII(UNHEX(tmp_rcode)) AS UNSIGNED);
  19.         IF lcode > 128 THEN
  20.             SET mycode =65536 - lcode * 256 - rcode ;
  21.             SELECT CONCAT(mypy,spell) INTO mypy FROM base_spell_code WHERE CODE >= ABS(mycode) ORDER BY CODE ASC LIMIT 1;
  22.             SET lp = lp + 4;
  23.         ELSE
  24.             SET mypy = CONCAT(mypy,CHAR(CAST(ASCII(UNHEX(SUBSTRING(NAME, lp, 2))) AS UNSIGNED)));
  25.             SET lp = lp + 2;
  26.         END IF;
  27.     END WHILE;
  28.     RETURN LOWER(mypy);
  29. END $$
  30. delimiter ;



参考:

http://my.oschina.net/u/1273696/blog/181995
http://blog.csdn.net/god123209/article/details/7577138
阅读(1496) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~