1366-incorrect string value: ' \xe4\xb8\xad\xe6\x96\x87 ' for column ' CName ' at row 1

Source: Internet
Author: User

1. Explanation:

This is a custom mysq error that is reported at run time

function of 2.Mysql:

CREATE FUNCTION ' getclassname ' (classId INTEGER)
RETURNS varchar (CHARSET) UTF8
Deterministic
BEGIN
DECLARE cName VARCHAR () DEFAULT ';
SELECT ' name ' into the CName from class where cid=classid;
return cName;
End;

3. Analysis:

The meaning of the error is that this function is defined in the first line of CNAME this field is given the wrong string value: ' \xe4\xb8\xad\xe6\x96\x87 '

In fact, the value of the variable in the function received is inconsistent with its definition, but why does the varchar type disagree?

And then carefully check that it is assigned to the value inside must have Chinese inside, so the problem lies in Chinese, to solve this problem need to let CNAME this variable can receive Chinese only, so the above CNAME statement modified as follows:

CREATE FUNCTION ' Newproc ' (classId INTEGER)
RETURNS varchar (CHARSET) UTF8
Deterministic
BEGIN
DECLARE cName VARCHAR (m) CHARSET UTF8 DEFAULT ";
SELECT ' name ' into the CName from class where cid=classid;
return cName;
End;

is to specify the encoding format after the declaration CNAME: CHARSET UTF8

Run this function again, and the result will not be an error in Chinese.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.