首页 > 解决方案 > 为什么 MySQL substr 在长度超过 512 时返回数据类型 Text 中的值?

问题描述

我注意到当长度超过 512 时,MySQL substr() 返回数据类型文本中的值。

请检查以下示例;

数据表:

create table temp10( c0 int primary key auto_increment, c1 varchar(2500));
insert into temp10(c1) values ('abcd');

使用 temp10 作为源的辅助表;

create table temp11 as
    select c1, 
    substr(c1, 1, 10) as c2, 
    substr(c1, 1, 100) as c3, 
    substr(c1, 1, 512) as c4, 
    substr(c1, 1, 513) as c5, 
    substr(c1, 1, 2500) as c6
    from temp10; 

创建的表的结构是;

表:temp11 列:

c1 varchar(2500) 
c2 varchar(10) 
c3 varchar(100) 
c4 varchar(512) 
c5 text 
c6 text

这是预期/记录的行为吗?

对于嵌套在 select 子句中的子查询,也注意到了同样的行为。

标签: mysqltextvarcharsubstr

解决方案


推荐阅读