Quote:
Originally Posted by varghese Begin End Examples
mysql>
mysql> DELIMITER //
mysql> CREATE FUNCTION myProcedure (rate DECIMAL(10,2))
-> RETURNS DECIMAL(10,2)
->
-> SQL SECURITY DEFINER
->
-> tax: BEGIN
-> DECLARE discount DECIMAL(10,2);
-> SET discount = rate * .05;
-> RETURN discount;
-> END
-> //
Query OK, 0 rows affected (0.00 sec)
mysql> DELIMITER ;
mysql>
mysql> select myProcedure(123.45);
+----------------+
| myProcedure(123.45) |
+----------------+
| 6.17 |
+----------------+
1 row in set, 1 warning (0.00 sec)
mysql>
mysql> drop function myProcedure;
Query OK, 0 rows affected (0.00 sec)
mysql> |
I worked out same code given, but returns with error
Code:
This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)
May be here is suitable syntax for creating a stored function,
Code:
DROP FUNCTION IF EXISTS myProcedure;
CREATE FUNCTION myProcedure (rate DECIMAL(10,2)) RETURNS DECIMAL(10,2)
DETERMINISTIC
COMMENT 'Simple Function'
SQL SECURITY DEFINER
BEGIN
DECLARE discount DECIMAL(10,2);
SET discount = rate * .05;
RETURN discount;
END;