DELIMITER //
CREATE FUNCTION StrToTime(dateformat varchar(50),timeslot varchar(50),mark int)
Returns varchar(50)
Begin
declare year1 varchar(50);
declare month1 varchar(50);
declare day1 varchar(50);
declare hour1 varchar(50);
declare minminute varchar(50);
declare minute1 varchar(50);
declare str varchar(50);
declare returnstr varchar(50);
declare lennum int;
select lennum=len(dateformat)-len(replace(dateformat,'-',''));
set year1 =left(dateformat,charindex('-',dateformat)-1);
set str = stuff(dateformat,1,charindex('-',dateformat),'');
set returnstr='';
if ennum =3 and timeslot ='0' then
set month1= left(str,charindex('-',str)-1);
set str = stuff(str,1,charindex('-',str),'');
set day1 = left(str,charindex('-',str)-1);
set hour1 = stuff(str,1,charindex('-',str),'');
if mark =0 then
set returnstr = year1 + '-' + month1 + '-' + day1 + ' ' + hour1 + ':00:00';
else
set returnstr = year1 + '-' + month1 + '-' + day1 + ' ' + hour1 + ':59:59';
end if;
end if;
/********************** --年-月-日-时(有分钟) **********************/
if lennum =3 and timeslot !='0' then
set month1 = left(str,charindex('-',str)-1);
set str = stuff(str,1,charindex('-',str),'');
set day1 = left(str,charindex('-',str)-1);
set hour1 = stuff(str,1,charindex('-',str),'');
/** set minminute =convert(varchar,convert(int,left(timeslot,instr('-',timeslot)-1)));****/
set minminute =convert(convert(left(timeslot,instr('-',timeslot)-1),SIGNED),char);
if minminute='0' then
set minminute ='00';
else
set minute1 = convert(reverse(left(reverse(timeslot),charindex('-',reverse(timeslot))-1))-1,char);
if mark =0 then
set returnstr = year1 + '-' + month1 + '-' + day1 + ' ' + hour1 +':'+minminute+':00';
else
set returnstr = year1 + '-' + month1 + '-' + day1+ ' ' + hour1 +':'+minute1+ ':59';
end if;
end if;
/** 年-月-日 **/
if lennum =2 then
set month1 = left(str,charindex('-',str)-1);
set str = stuff(str,1,charindex('-',str),'');
set day1 = str;
if mark =0 then
set returnstr = year1 + '-' + month1 + '-' + day1 + ' ' + '00:00:00';
else
set returnstr = year1 + '-' + month1 + '-' + day1 + ' ' +'23:59:59';
end if;
end if;
/** 年-月**/
if lennum =1 then
set month1 = str;
if month1='12' then
set day1=31;
else
select day1= datediff(convert(year1+'-'+month1+'-'+'1',datetime),convert(year1+'-'+convert(convert(month1,signed)+1,char)+'-'+'1',datetime)) ;
end if;
if mark =0 then
set returnstr = dateformat + '-' + '1' + ' ' + '00:00:00';
else
set returnstr = dateformat + '-' + day1 + ' ' + '23:59:59';
end if;
end if;
Return returnstr;
End //
DELIMITER ;
提示错误:谁帮忙看看 right syntax to use near '//' at line 90.
最好是 复制下来 执行下. 新人刚接触 mysql
自己的 if语句 写错了. 晕,真难找~~ 眼花
解决了就好
错误提示你:在第90行使用的"//"是错误的,叫你正确使用
大哥,我也懂提示。但是我看不懂 哪里写错了。
百度的案例 也是这么写的。 end 后面 加 前面定义的 符号. // .
DELIMITER // begin ..... end // DELIMITER ; 这种格式
而且 我删了 // 也会提示我错误。只不过是 把//换成了 ''
right syntax to use near '' at line 90.
@漠明奇喵: 我也找不到答案
@我只是慕名而来: 嗯,那也感谢你抽时间看我的问题。