2013-05-07 54 views
0
My stored procedure is like this ... 



DELIMITER $$ 

DROP PROCEDURE IF EXISTS `tds_dev`.`BlockTokenSheduler`$$ 

CREATE PROCEDURE `BlockTokenSheduler`(cdate date,shift varchar(20)) 
BEGIN 
     declare lo_SERIALNO int; 
     declare lo_TOKENNUMBER int; 
     declare lo_ARRIVALTIME time; 
     declare lo_ADJUSTMENTTIME time; 
     declare lo_APPOINTMENTTIME time; 
     declare bt_ADJUSTMENTTIME time; 
     declare bt_NEXTAPPOINTMENTTIME time; 
     declare lo_CONSULTATIONTYPE varchar(20); 
     declare lo_NEXTAPPOINTMENTTIME time; 
     declare lo_CONSULTATIONSTATUS varchar(20); 
     declare lo_ACTUALFINISHEDTIME time; 
     declare lo_SMSSTATUS varchar(20); 
     declare temp_appTime time; 
     declare time_diff time; 
     declare done int; 
     declare btdone int; 
     declare btcount int; 
     declare co int; 
      Declare btcountcur Cursor for 
      select ADJUSTMENTTIME,NEXTAPPOINTMENTTIME from tds_tokengeneration where TOKENDATE =cdate and SHIFTID = shift and blockstatus='BT' ORDER BY APPOINTMENTTIME ; 

      declare continue handler for not found set btdone=1; 


      open btcountcur; 


      bt_loop :LOOP 

       if btdone=1 then 
        leave bt_loop; 
        end if; 

       FETCH btcountcur into bt_ADJUSTMENTTIME,bt_NEXTAPPOINTMENTTIME; 

        Declare mycur cursor for 
       select TOKENNUMBER,APPOINTMENTTIME,ADJUSTMENTTIME,CONSULTATIONTYPE,NEXTAPPOINTMENTTIME,CONSULTATIONSTATUS,SMSSTATUS from tds_tokengeneration 
       where TOKENDATE=cdate and SHIFTID=shift and blockstatus='MT'; 
          declare continue handler for not found set done=1; 
        open mycur; 
        time_loop :LOOP 
        FETCH mycur into lo_TOKENNUMBER,lo_APPOINTMENTTIME,lo_ADJUSTMENTTIME, 
           lo_CONSULTATIONTYPE,lo_NEXTAPPOINTMENTTIME,lo_CONSULTATIONSTATUS,lo_SMSSTATUS; 
        if done=1 then 
        leave time_loop; 
        end if; 

       if (lo_ADJUSTMENTTIME >= bt_ADJUSTMENTTIME and lo_APPOINTMENTTIME <= bt_NEXTAPPOINTMENTTIME) or (lo_NEXTAPPOINTMENTTIME >= bt_ADJUSTMENTTIME and lo_NEXTAPPOINTMENTTIME <= bt_NEXTAPPOINTMENTTIME)then 

       set lo_ADJUSTMENTTIME=bt_NEXTAPPOINTMENTTIME; 
       if lo_CONSULTATIONTYPE='C' then 
         set lo_NEXTAPPOINTMENTTIME = ADDTIME(lo_ADJUSTMENTTIME,'00:12:00'); 
        else 
         set lo_NEXTAPPOINTMENTTIME = ADDTIME(lo_ADJUSTMENTTIME,'00:20:00'); 
        end if; 
       update tds_tokengeneration set ADJUSTMENTTIME=lo_ADJUSTMENTTIME, 
          NEXTAPPOINTMENTTIME=lo_NEXTAPPOINTMENTTIME, 
          SMSSTATUS=lo_SMSSTATUS 
          where TOKENNUMBER=lo_TOKENNUMBER and TOKENDATE=cdate and SERIALNO=lo_SERIALNO; 
       end if; 
      end loop time_loop; 
      close mycur; 

     end loop bt_loop; 
    close btcountcur; 

    END$$ 

DELIMITER ; 

。但當我執行這個程序我得到以下錯誤錯誤在存儲過程(錯誤代碼:1064)

(0 row(s)affected) 
(0 ms taken) 

Error Code : 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 'Declare mycur cursor for 
       select TOKENNUMBER,APPOINTMENTTIME,ADJ' at line 33 
(0 ms taken) 

回答