Database Reference
In-Depth Information
To display the total you can then do the following:
Input
SELECT @total;
Output
+--------+
| @total |
+--------+
| 149.87 |
+--------+
Analysis
@total has already been populated by the CALL statement to ordertotal ,
and SELECT displays the value it contains.
To obtain a display for the total of another order, you would need to call the
stored procedure again, and then redisplay the variable:
Input
CALL ordertotal(20009, @total);
SELECT @total;
Building Intelligent Stored Procedures
All the stored
procedures used thus far have basically encapsulated simple
MariaDB SELECT statements. And while they are all valid examples of stored
procedures, they really don't do anything more than what you could do with
those statements directly (if anything, they just make things a little more com-
plex). The real power of stored procedures is realized when business rules and
intelligent processing are included within them.
Consider this scenario. You need to obtain order totals as before, but also need
to add sales tax to the total, but only for some customers (perhaps the ones in
your own state). Now you need to do several things:
Obtain the total (as before).
Conditionally add tax to the total.
Return the total (with or without tax).
That's a perfect job for a stored procedure:
 
 
Search WWH ::




Custom Search