赞
踩
# 查询文章指定字符长度
-- note_text数据类型为text
SELECT note_id, CONVERT(note_text, VARCHAR(10)) as note_text_desc
FROM productnotes;
/*错误结果:1064 - You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version
for the right syntax to use near 'VARCHAR(10)) as note_text_desc
FROM productnotes' at line 1*/
转化格式仅仅支持 BINARY、CHAR、DATE、DATETIME、TIME、DECIMAL、SIGNED、UNSIGNED 数据类型。
使用char型代替可实现该功能,如下图例子
SELECT note_id, CONVERT(note_text, CHAR(10)) as note_text_desc FROM productnotes; /* result: 101 Customer c 102 Can shippe 103 Safe is co 104 Quantity v 105 Included f 106 Matches no 107 Please not 108 Multiple c 109 Item is ex 110 Customer c 111 Shipped un 112 Customer c 113 Customer c 114 Call from */
如需具体了解mysql的cast()和convert()使用请参见MySQL 8 中的数据类型转换
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。