MySQL Forums
Forum List  »  Stored Procedures

Create Function as Stored Procedure
Posted by: Scott Chilton
Date: December 05, 2008 10:46AM

I am new to MySql and am trying to create a function that can be called in a query. It is my understanding that the function needs to be defined as a stored procedure. I have attempted to create the function below, but cannot get it to compile. Any assistance you may provide in correcting the syntax would be greatly appreciated.


DELIMITER $
CREATE FUNCTION bmonth (date1 DATE, cycle CHAR(20))
RETURNS INT
BEGIN
DECLARE bmonth INT;
DECLARE dmonth INT;
DECLARE dday INT;
DECLARE c INT;
SET dmonth=month(date1);
SET dday=day(date1);
case cycle
when "01" then set c=1;
when "02" then set c=2;
when "03" then set c=3;
when "04" then set c=4;
when "05" then set c=5;
when "06" then set c=6;
when "07" then set c=7;
when "08" then set c=8;
when "09" then set c=9;
when "10" then set c=10;
when "11" then set c=11;
when "12" then set c=12;
when "13" then set c=13;
when "14" then set c=14;
when "15" then set c=15;
when "16" then set c=16;
when "17" then set c=17;
when "18" then set c=18;
when "19" then set c=19;
when "20" then set c=20;
when "21" then set c=21;
Else
set c=99;
end case;
if and(dday>25,c<6) then
set bmonth=dmonth + 1;
else
set bmonth=dmonth;
end if;
return bmonth;
END;
$

Options: ReplyQuote


Subject
Views
Written By
Posted
Create Function as Stored Procedure
3351
December 05, 2008 10:46AM
1608
December 05, 2008 10:53AM
1698
December 05, 2008 03:31PM
1610
December 05, 2008 03:32PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.