BEGIN and END Statements

mysql>
mysql> DELIMITER //
mysql> CREATE FUNCTION myProc (cost DECIMAL(10,2))
    -> RETURNS DECIMAL(10,2)
    ->
    -> SQL SECURITY DEFINER
    ->
    -> tax: BEGIN
    ->     DECLARE order_tax DECIMAL(10,2);
    ->     SET order_tax = cost * .05;
    ->     RETURN order_tax;
    -> END
    -> //
Query OK, rows affected (0.00 sec)

mysql> DELIMITER&nbsp$$
mysql>
mysql> select myProc(123.45);
+—————-+
| myProc(123.45|
+—————-+
|           6.17 |
+—————-+
row in set, warning (0.00 sec)

mysql>
mysql> drop function myProc;
Query OK, rows affected (0.00 sec)

mysql>


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.