BEGIN and END Statements : Begin End : Procedure Function MySQL TUTORIALS


MySQL TUTORIALS » Procedure Function » Begin End »

 

BEGIN and END Statements


BEGIN and END statements group statements in procedures with more than one SQL statement.

Declarations can be made only within a BEGIN ... END block.

You can define a label for the block to clarify your code.

The labels must match exactly.

yourLableName: BEGIN
<SQL statement>;
<SQL statement>;
END yourLableName
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 ;
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 Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

MySQL TUTORIALS

 Navioo Procedure Function
» Begin End