MySQL-Cómo seleccionar datos por longitud de cadena


SELECT * FROM table ORDER BY string_length(column);

¿Hay una función MySQL para hacer esto (por supuesto en lugar de string_length)?

Author: hsz, 2009-12-09

4 answers

Usted está buscando CHAR_LENGTH() para obtener el número de caracteres de una cadena.

Para conjuntos de caracteres multibyte LENGTH() le dará el número de bytes que ocupa la cadena, mientras que CHAR_LENGTH() devolverá el número de caracteres.

 405
Author: hsz,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-09-10 18:04:30
select * from table order by length(column);

La documentación sobre la función length (), así como todas las demás funciones de cadena, está disponible aquí.

 67
Author: Kaleb Brasee,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-12-09 00:51:40

Echando un vistazo a la documentación de MySQL para las funciones de cadena, también podemos usar CHAR_LENGTH() y CHARACTER_LENGTH() también.

 26
Author: NeverHopeless,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-06-27 08:26:28

La función que uso para encontrar la longitud de la cadena es length, usada de la siguiente manera:

SELECT * FROM table ORDER BY length(column);
 0
Author: Rito,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-09-01 07:47:30