DELIMITER $$ DROP FUNCTION IF EXISTS `test`.`is_initial` $$ CREATE FUNCTION `test`.`is_initial` (f varchar(255)) RETURNS BOOL BEGIN SET @is_initial = false; CASE f WHEN NULL THEN SET @is_initial = TRUE; WHEN '' THEN SET @is_initial = TRUE; ELSE SET @is_initial = FALSE; END CASE; RETURN @is_initial; END $$ DELIMITER ;
Sunday, October 22, 2006
Handy MySQL function
Here is a simple function that can help coping with wrong database design, when you have a mix of NULLs and blank fields meaning the same, no value, which they shouldn't.
Subscribe to:
Post Comments (Atom)
2 comments:
Just pointing out a typo for ya...
Line 11: #
WHEN NULL THEN SET @is_iniali = TRUE;
I'm guessing should be #
WHEN NULL THEN SET @is_initial = TRUE;
Yes, typo corrected, thank you
Post a Comment