我试着使用这些mysql函数来处理波斯文日期,我得到了这个错误,但是我不能解决它
SQL query:
CREATE FUNCTION `persian_day` (
indate date
) RETURNS int( 11 ) BEGIN declare j int;
MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3 我使用mysqlnd 5.0.8-dev和phpmyadmin (xampp包)
下面是我的函数
CREATE FUNCTION `persian_mod`(a double,b double) RETURNS int(11)
return (a - b * floor(a / b))
CREATE FUNCTION `persian_div`(a double,b double) RETURNS int(11)
return (floor(a / b))
CREATE FUNCTION `persian_pj`(y int,m int,d int) RETURNS int(11)
return ( 227260 +
1029983 * persian_div((y - 474), 2820) +
365 * ( (persian_mod((y - 474), 2820) + 474) - 1) +
persian_div(682 * (persian_mod((y - 474), 2820) + 474) - 110, 2816) +
if(m > 6, 30 * m + 6, 31 * m)
+ d )
CREATE FUNCTION `persian_day`(indate date) RETURNS int(11)
begin
declare j int;
declare a int;
declare b int ;
declare c int;
declare d int;
declare yearr int;
declare f double;
declare monthh int;
set j=TO_DAYS(indate) ;
set a = j - persian_pj(475, 0, 1) ;
set b = persian_div(a, 1029983) ;
set c = persian_mod(a, 1029983) ;
set d = if(c <> 1029982, persian_div(2816 * c + 1031337, 1028522), 2820) ;
set yearr = 474 + 2820 * b + d;
set f = (1 + j) - persian_pj(yearr, 0, 1);
set monthh= if(f > 186, ceil((f - 6) / 30) - 1, ceil(f / 31) - 1);
return (j - (persian_pj(yearr, monthh, 1) - 1));
end为什么会出现这个错误?如何解决?
发布于 2012-08-11 09:59:54
创建函数时的基本语法是您应该有一个return语句。
CREATE FUNCTION fnctionName (paramList)
RETURNS datatype
BEGIN
RETURN valueToReturn;
END但是如果你在你的函数中有特殊的计算(当然是多行),你需要首先改变分隔符:
DELIMITER $$
CREATE FUNCTION fnctionName (paramList)
RETURNS datatype
BEGIN
DECLARE ....;
..... other codes ;
RETURN valueToReturn;
END $$
DELIMITER ;回到你的案例中,
CREATE FUNCTION `persian_day` (indate date) RETURNS int( 11 )
BEGIN
declare j int;您没有RETURN值,也没有使用END关键字关闭函数。就像您在您创建的其他函数上所做的那样。
https://stackoverflow.com/questions/11911137
复制相似问题