使用Mysql的奇怪之处(5.6.39) 我想在视图中创建一些varchar数据类型的文本。 只是示例(如果我使用真实表中的实际数据,也会发生同样的事情):
最长可达512
CREATE
algorithm = UNDEFINED
SQL SECURITY DEFINER
view conversiontest2(field1) as
select cast('sometext' as char(512) charset utf8);
结果:
MySQL [xx]> show columns from conversiontest2;
+--------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+--------------+------+-----+---------+-------+
| field1 | varchar(512) | NO | | | |
+--------+--------------+------+-----+---------+-------+
如果我使用任何大于512的值
> ALTER
-> algorithm = UNDEFINED
-> SQL SECURITY DEFINER
-> view conversiontest2(field1) as
-> select cast('sometext' as char(513) charset utf8)
-> ;
Query OK, 0 rows affected (0.00 sec)
MySQL [xx]> show columns from conversiontest2;
+--------+------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+------+------+-----+---------+-------+
| field1 | text | NO | | NULL | |
+--------+------+------+-----+---------+-------+
1 row in set (0.00 sec)
我错过了什么?
相同的结果(当然)使用convert()而不是cast()..