Return NUMERIC(8,2) from a function : Function Returning : Procedure Function MySQL TUTORIALS


MySQL TUTORIALS » Procedure Function » Function Returning »

 

Return NUMERIC(8,2) from a function


mysql>
mysql>
mysql> delimiter $$
mysql> CREATE FUNCTION myFunction(normal_price NUMERIC(8,2))
    -> RETURNS NUMERIC(8,2)
    -> BEGIN
    ->
    ->     DECLARE discount_price NUMERIC(8,2);
    ->
    ->     IF (normal_price>500THEN
    ->        SET discount_price=normal_price*.8;
    ->     ELSEIF (normal_price>100THEN
    ->        SET discount_price=normal_price*.9;
    ->     ELSE
    ->        SET discount_price=normal_price;
    ->     END IF;
    ->     RETURN(discount_price);
    -> END$$
Query OK, rows affected (0.00 sec)

mysql> delimiter ;
mysql>
mysql> select myFunction(123.123);
+---------------------+
| myFunction(123.123|
+---------------------+
|              110.81 |
+---------------------+
row in set, warnings (0.02 sec)

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

mysql>
mysql>



Leave a Comment / Note


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

Follow Navioo On Twitter

MySQL TUTORIALS

 Navioo Procedure Function
» Function Returning