View Single Post
  #2 (permalink)  
Old 11-10-2007, 01:17 AM
Murali Murali is offline
D-Web Master
 
Join Date: Feb 2007
Location: India-Chennai.
Posts: 386
Murali is on a distinguished road
Send a message via AIM to Murali
Default Re: Procedure Function

Quote:
Originally Posted by varghese View Post
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;
__________________
-Murali..

Last edited by Murali : 11-10-2007 at 01:19 AM.
Reply With Quote