4

我需要知道如何获取 mysql 中特定列的最大大小,该表是

转:

CREATE TABLE `turno` (  
`idTurno` tinyint(4) NOT NULL,  
`nombreTurno` varchar(20) COLLATE utf8_spanish2_ci NOT NULL,  
`horaInicio` tinyint(4) NOT NULL,  
`horafin` tinyint(4) NOT NULL,  
`valorTurno` int(11) NOT NULL,  
PRIMARY KEY (`idTurno`)) 
ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish2_ci

专栏:

`nombreTurno` varchar(20) COLLATE utf8_spanish2_ci NOT NULL

我应该得到:

20

我越来越:

NULL

查询:

SELECT MAX( LENGTH( nombreTurno ) ) AS maxl
FROM turno

希望你能帮助我,谢谢

4

2 回答 2

16
select COLUMN_NAME, CHARACTER_MAXIMUM_LENGTH 
from information_schema.columns
where table_schema = DATABASE() AND   -- name of your database
      table_name = 'turno' AND        -- name of your table
      COLUMN_NAME = 'nombreTurno'     -- name of the column
于 2013-03-12T17:16:13.260 回答
1

以下 SQL 查询将给出最大列长度。

SELECT max(length(column)) `max_column_length` from tab;
于 2020-10-02T10:16:20.227 回答