Database Reference
In-Depth Information
has changed so the result is stored in
total
(the local variable) instead of
oto-
tal
. Then an
IF
statement checks to see whether
taxable
is true, and if it is,
another
SELECT
statement is used to add the tax to local variable
total
. And
finally,
total
(which might or might not have had tax added) is saved to
oto-
tal
using another
SELECT
statement.
Tip
The
COMMENT
Keyword The stored procedure for this example included a
COMMENT
value in the
CREATE PROCEDURE
statement. This is not required, but if specified, is
displayed in
SHOW PROCEDURE STATUS
results.
This is obviously a more sophisticated and powerful stored procedure. To try it
out, use the following two statements:
▼
Input
CALL ordertotal(20005, 0, @total);
SELECT @total;
▼
Output
+--------+
| @total |
+--------+
| 149.87 |
+--------+
▼
Input
CALL ordertotal(20005, 1, @total);
SELECT @total;
▼
Output
+---------------+
| @total |
+---------------+
| 158.862200000 |
+---------------+
▼
Analysis
BOOLEAN
values may be specified as
1
for true and
0
for false (actually, any
nonzero value is considered true and only
0
is considered false). By specifying
0
or
1
in the middle parameter you can conditionally add tax to the order total.