Blogger Information
Blog 7
fans 0
comment 0
visits 8081
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
#1366 - Incorrect string value: '\xE6\x96\xB0\xE9\x97\xBB' for column 'cate_name' at row 1
那山的博客
Original
3093 people have browsed it

1.解释:

这是一个自定义的Mysq函数在运行时候所报的错误

2.Mysql的函数:

CREATE FUNCTION `getClassName`(classId INTEGER)
 RETURNS varchar(50) CHARSET utf8
    DETERMINISTIC
BEGIN
DECLARE cName VARCHAR(50)  DEFAULT '';
SELECT `name` INTO cName from class where cid=classId;
RETURN cName;
END;

3.分析:

报错的含义就是此函数在第一行定义的cName这个字段被赋予了错误的字符串值:'\xE4\xB8\xAD\xE6\x96\x87'

实际上就函数里面的变量接收到的值跟它定义的不一致,但是一看还是varchar类型为什么会不一致呢?

再仔细检查它被赋予的值里面一定是有中文在里面的,所以问题就在于中文,要解决这个问题就需要让cName这个变量可以接收中文才行,于是把上面的cName声明修改如下:

CREATE FUNCTION `NewProc`(classId INTEGER)
 RETURNS varchar(50) CHARSET utf8
    DETERMINISTIC
BEGIN
DECLARE cName VARCHAR(50) CHARSET utf8  DEFAULT '';
SELECT `name` INTO cName from class where cid=classId;
RETURN cName;
END;

就是在声明cName的后面给它指定了编码格式:CHARSET utf8

再次运行此函数,结果中有中文也不会报错了。


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!