mysql encode(,)函数出错。

afternoone 2009-05-13 06:51:10
我在mysql 中建了个表,用下面的insert 插入数据时会也错,请指教:
建表如下:
create table teacher(
id int(5) auto_increment not null primary key,
name char(128) not null
);
有错的插入方法如下:
insert into teacher values(Null,encode('il','df'));
insert into teacher values(NULL,encode('i','df'));

错误:incorrect string value: '\xc0' for column 'name' at row 1

如果这样插入就不会有错:
insert into teacher values(NULL,encode('somevalue','somepass'));

为什么呢?
请指教,thanks

...全文
266 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
panhg 2010-12-19
  • 打赏
  • 举报
回复
谢谢 赐教
afternoone 2009-06-11
  • 打赏
  • 举报
回复
thanks ,受教了!!
ACMAIN_CHM 2009-05-13
  • 打赏
  • 举报
回复

字符集的问题

mysql> select charset(encode('il','df'));
+----------------------------+
| charset(encode('il','df')) |
+----------------------------+
| binary |
+----------------------------+
1 row in set (0.00 sec)

mysql>



mysql> create table teacher(
-> id int(5) auto_increment not null primary key,
-> name char(128) not null
-> ) DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.09 sec)

mysql> insert into teacher values(Null,encode('il','df'));
ERROR 1366 (HY000): Incorrect string value: '\xC0"' for column 'name' at row 1

mysql> alter table teacher MODIFY `name` char(128) CHARACTER SET binary;
Query OK, 0 rows affected (0.14 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql>
mysql> insert into teacher values(Null, encode('il','df'));
Query OK, 1 row affected (0.06 sec)

mysql>


56,679

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧