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