Showing entries 1 to 1
Displaying posts with tag: espaces (reset)
collapseSpaces

Besoin d’éliminer les espaces multiples pour les remplacer par un seul?  J’ai ce qu’il vous faut!

 

SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='STRICT_TRANS_TABLES';
DROP FUNCTION IF EXISTS collapseSpaces;

DELIMITER //
CREATE FUNCTION collapseSpaces ( stringparam VARBINARY(255))
RETURNS VARBINARY(255)
DETERMINISTIC
LANGUAGE SQL
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT 'Returns a string with all spaces replaced/merged by/into a single space character'

BEGIN
DECLARE newString VARBINARY(255);
DECLARE hasChanged TINYINT UNSIGNED;
DECLARE oldLength TINYINT UNSIGNED;

SET hasChanged = 1;
SET newString = stringparam;
SET oldLength = CHAR_LENGTH(stringparam);

WHILE hasChanged DO
SET newString = REPLACE(newString, ' ', ' ');
SET hasChanged = (oldLength != CHAR_LENGTH(newString));
SET oldLength = CHAR_LENGTH(newString);
END WHILE; …
[Lire plus]
Showing entries 1 to 1