MYSQL语法排错!

gungod 2011-03-18 02:28:32
下面创建的函数过程,哪个地方不对?


DROP FUNCTION IF EXISTS fn_isreplace;
delimiter //
Create function fn_isreplace
(`update` datetime,timezone int)
returns int
begin
declare `curtime` datetime;
declare curlttime datetime;
declare curutctime datetime;
declare re_sec int;
set `curtime` = NOW();
set curutctime = CONVERT_TZ(NOW(),'+08:00','+00:00');

if `update` <> 0 then
begin
if timezone >= 1 then
set `curtime` = CONVERT_TZ(NOW(),'+08:00','+00:00');
else
begin
if curutctime - curlttime = 0 then
set `curtime` = curutctime;
else
set `curtime` = curlttime;
end if;
end;
end if;
set re_sec = Round(Cast((`update` - `curtime`) as decimal),0);
end;
else
set re_sec = 0;

end if;
return re_sec;
end//
delimiter ;

...全文
66 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
ACMAIN_CHM 2011-03-21
  • 打赏
  • 举报
回复
估计是有什么不可见字符,比如中文全角的空格之类的。
gungod 2011-03-21
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 acmain_chm 的回复:]
引用 5 楼 gungod 的回复:
奇怪了,我删除SQL文件,再粘贴代码运行就没出错了,为什么了呢?
注释符的原因?

贴问题的时候,建议把错误信息一起贴出来,这样别人就不需要猜了。
[/Quote]
写了在3楼,发帖时漏了,后来修改的时候,说一回帖的问题没法再编辑了。
ACMAIN_CHM 2011-03-18
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 gungod 的回复:]
奇怪了,我删除SQL文件,再粘贴代码运行就没出错了,为什么了呢?
注释符的原因?
[/Quote]
贴问题的时候,建议把错误信息一起贴出来,这样别人就不需要猜了。
wwwwb 2011-03-18
  • 打赏
  • 举报
回复
有全角符?
gungod 2011-03-18
  • 打赏
  • 举报
回复
奇怪了,我删除SQL文件,再粘贴代码运行就没出错了,为什么了呢?
注释符的原因?
gungod 2011-03-18
  • 打赏
  • 举报
回复
你那有1个1 warning ?
zuoxingyu 2011-03-18
  • 打赏
  • 举报
回复

mysql> DROP FUNCTION IF EXISTS fn_isreplace;
Query OK, 0 rows affected, 1 warning (0.05 sec)

mysql> delimiter //
mysql> Create function fn_isreplace
-> (`update` datetime,timezone int)
-> returns int
-> begin
-> declare `curtime` datetime;
-> declare curlttime datetime;
-> declare curutctime datetime;
-> declare re_sec int;
-> set `curtime` = NOW();
-> set curutctime = CONVERT_TZ(NOW(),'+08:00','+00:00');
->
-> if `update` <> 0 then
-> begin
-> if timezone >= 1 then
-> set `curtime` = CONVERT_TZ(NOW(),'+08:00','+00:00');
-> else
-> begin
-> if curutctime - curlttime = 0 then
-> set `curtime` = curutctime;
-> else
-> set `curtime` = curlttime;
-> end if;
-> end;
-> end if;
-> set re_sec = Round(Cast((`update` - `curtime`) as decimal),0);
-> end;
-> else
-> set re_sec = 0;
->
-> end if;
-> return re_sec;
-> end//
Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;
mysql>


没有发现错误。
gungod 2011-03-18
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 mr_mablevi 的回复:]
没有错..
[/Quote]

运行后出错提示:

SQL Error(1064):You have an error in your SQL syntax;check the manual that corresponds to your MySQL server version for the right syntax to user near '' at line 20.


说明下,
我的Line 20代码是:
set `curtime` = CONVERT_TZ(NOW(),'+08:00','+00:00');
else
小小小小周 2011-03-18
  • 打赏
  • 举报
回复
没有错..

56,679

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧