For those of you interested in the solution: there are two different forms of the
CASE statement syntax: the so-called simple case and the searched case. The simple case selects one
WHEN...THEN branch by comparing the value of the expression that appears after the CASE keyword with the value of the expressions given in each of the WHEN...THEN branches. It enters the first branch found where the values are equal to one another:
CASE expr
WHEN expr1 THEN ...statements...
...
WHEN exprN THEN ...statements...
ELSE ...statements...
END CASE
The searched case syntax simply chooses the first
WHEN...THEN branch for which the condition appearing after the WHEN keyword is TRUE:
CASE
WHEN cond1 THEN ...statements...
...
WHEN condN THEN ...statements...
ELSE ...statements...
END CASE
The
p_find_slash procedure uses a simple case but accidentally used conditions the WHEN...THEN branches:
CASE v_char
WHEN v_char = '/' THEN ...
...
END CASE
What many people don't realize is that syntactically this is perfectly valid. That's because to MySQL, those conditions are simply particular types of expression. It's just that their value will be either
0 or 1 depending on whether the condition holds FALSE or TRUE respectively (consequently, the built-in constants FALSE and TRUE are in fact synonyms for 0 and 1 respectively).I already emailed a few of you, so if you didn't yet receive an email from me, send me your email address and I'll make sure you get the discount code. I can be reached via email:
Roland dot Bouman at gmail dot com
See you at the UC!