use mydb;
DROP TABLE IF EXISTS `hz2py`;
CREATE TABLE `hz2py` (
`PY` char(1) character set utf8 NOT NULL,
`HZ` char(1) NOT NULL default '',
PRIMARY KEY (`PY`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk;
INSERT INTO `hz2py` (`PY`,`HZ`) VALUES
('A','骜'),
('B','簿'),
('C','错'),
('D','鵽'),
('E','樲'),
('F','鳆'),
('G','腂'),
('H','夻'),
('J','攈'),
('K','穒'),
('L','鱳'),
('M','旀'),
('N','桛'),
('O','沤'),
('P','曝'),
('Q','囕'),
('R','鶸'),
('S','蜶'),
('T','箨'),
('W','鹜'),
('X','鑂'),
('Y','韵'),
('Z','咗');
CREATE FUNCTION `mydb`.`firstPY`(words varchar(255)) RETURNS mediumtext
BEGIN
declare fpy char(1);
declare pc char(1);
declare cc char(4);
set @fpy = UPPER(left(words,1));
set @pc = (CONVERT(@fpy USING gbk));
set @cc = hex(@pc);
if @cc >= "8140" and @cc <="FEA0" then
begin
select PY into @fpy from HZ2PY where hz>=@pc limit 1;
end;
end if;
Return @fpy;
END
存储过程:
DELIMITER $$
DROP PROCEDURE IF EXISTS `test`.`getPY` $$
CREATE PROCEDURE `test`.`getPY` (in words char(1) )
BEGIN
select distinct name from mytest where firstPY(name) like CONCAT(words,'%') order by name;
END $$
DELIMITER ;
posted on 2006-08-23 14:06
SIMONE 阅读(1205)
评论(0) 编辑 收藏