1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
CREATE FUNCTION `string_cleanUp` (
$StringToCleanUp VARCHAR(255) ,
$UnwelcomeString VARCHAR(32) ,
$Joker VARCHAR(1)
) RETURNS varchar(255) CHARSET utf8
BEGIN
/* ============================================================================================================================
** string_cleanUp() Nettoyage d'une chaine de caractère (retrait de caractères indésirable'
** ----------------------------------------------------------------------------------------------------------------------------
** TRANSACTIONNELLE : NON
** CHECK-IN : OUI
** ETAT : Testée
** ----------------------------------------------------------------------------------------------------------------------------
** Auteur : IT-DaaS - Isabelle LE TRONG
**
** Versions : 1.0 2014-05-11 Version initiale
** -----------------------------------------------------------------------------------------------------------------------------
** PARAMETRES
**
** $StringToCleanUp VARCHAR(255) : Chaine de caractères à nettoyer
** $UnwelcomeString VARCHAR(32) : Caractères indésirables
** $Joker VARCHAR(1) : Caractère de substitution (espace, string vide,...)
** ==============================================================================================================================
**
** (V) Variables Locales
*/
DECLARE $Version DECIMAL(4,2) UNSIGNED DEFAULT 1.0 ;
DECLARE $UnwelcomeStringSize TINYINT(5) UNSIGNED ;
DECLARE $UnwelcomeStringIndex TINYINT(5) ;
DECLARE $String VARCHAR(255) ;
/*
** (H) HANDLERs
*/
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
SET $String = NULL ;
RETURN $String ;
END ;
/*
** (0) Set internal datas
*/
SET $UnwelcomeStringSize = CHAR_LENGTH($UnwelcomeString) ;
SET $UnwelcomeStringIndex = $UnwelcomeStringSize ;
SET $String = $StringToCleanUp ;
/*
** (1) Cleanup String
*/
WHILE ($UnwelcomeStringIndex > 0)
DO SET $String = REPLACE($String, SUBSTRING($UnwelcomeString, $UnwelcomeStringIndex,1), $Joker) ;
SET $UnwelcomeStringIndex = $UnwelcomeStringIndex - 1 ;
END WHILE ;
/*
** (EXIT)
*/
RETURN $String ;
END$$ |
Partager