title: Cursor in stored procedure of mysql not working
body: <p>I am using following stored procedure and calling a cursor inside it but it is returning me zero data fetched or processed what is wrong in the procedure ?</p>
  
  <pre><code>DELIMITER $$
  
  CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_ProcessData`(
  DummyDate datetime
  )
  BEGIN
  DECLARE MONTH BIGINT;
  DECLARE YEAR BIGINT;
  declare LBrCode VARCHAR(100);
  declare EntryDate datetime;
  declare VcrAcctId char(32);
  declare DrCr VARCHAR(100);
  declare FcyTrnAmt VARCHAR(100);
  DECLARE CustName char(50);
  DECLARE CreditAmount decimal(18,2);
  DECLARE DebitAmount decimal(18,2);
  DECLARE BatchCd char(15);
  DECLARE SetNo BIGINT;
  DECLARE ScrollNo BIGINT;
  DECLARE BookType char(10);
  DECLARE ActualAcctId varchar(50);
  DECLARE ActualBrCode varchar(50);
  DECLARE ActualBookType varchar(50);
  declare curProcessAMLData cursor
  
      for
  
      select distinct * from DummyTable 
      WHERE EntryDate = DummyDate
      AND (ActualBookType = 'XX');
      open curProcessAMLData;
      fetch next from curProcessAMLData into LBrCode,EntryDate,VcrAcctId,DrCr,FcyTrnAmt,BatchCd,SetNo,ScrollNo,BookType,ActualAcctId,ActualBrCode,ActualBookType;
      while fetch_status = 0
      DO  
                  SET MONTH = MONTH(DummyDate);
                  SET YEAR = MONTH(DummyDate);
                  IF(DrCr = 'C')
                  THEN
                      SET CreditAmount = FcyTrnAmt;
                      IF NOT EXISTS (SELECT * FROM Master WHERE BranchCode = ActualBrCode AND AccNo = ActualAcctId AND TransMonth = MONTH and TransYear = YEAR)
                      THEN
  
                          INSERT INTO Master
                          (
                              TransDate,
                              BranchCode,
                              AccNo,
                              Credit,
                              TransMonth,
                              TransYear
                          )
                          SELECT
  
                                    EntryDate,
                                    ActualBrCode,
                                    ActualAcctId,
                                    CreditAmount,
                                    MONTH,
                                    YEAR
                      END;
                      ELSE
                          UPDATE Master
                              SET Credit = IFNULL(Credit,0) + CreditAmount
                              WHERE BranchCode = ActualBrCode AND AccNo = ActualAcctId 
                              AND MONTH(TransDate) = MONTH 
                                  AND YEAR(TransDate) = YEAR;
                      END IF;
                  ELSE
                      SET DebitAmount = FcyTrnAmt;
                      IF NOT EXISTS (SELECT * FROM Master WHERE BranchCode = ActualBrCode AND AccNo = ActualAcctId AND TransMonth = MONTH and TransYear = YEAR)
                      THEN
  
                          INSERT INTO Master
                          (
                              TransDate,
                              BranchCode,
                              AccNo,
                              Debit,
                              TransMonth,
                              TransYear
                          )
                          SELECT
  
                                    EntryDate,
                                    ActualBrCode,
                                    ActualAcctId,
                                    DebitAmount,
                                    MONTH,
                                    YEAR
                      END;
                      ELSE
                              UPDATE Master
                              SET Debit = IFNULL(Debit,0) + DebitAmount
                              WHERE BranchCode = @ActualBrCode AND AccNo = ActualAcctId 
                              AND MONTH(TransDate) = MONTH 
                                  AND YEAR(TransDate) = YEAR;
  
                  END IF;
                  END IF;
          SET FcyTrnAmt = 0 ;
      END WHILE;  
  fetch next from curProcessAMLData
   into LBrCode,EntryDate,VcrAcctId,DrCr,FcyTrnAmt,BatchCd,SetNo,ScrollNo,BookType,ActualAcctId,ActualBrCode,ActualBookType;
  CLOSE curProcessAMLData;
  END
  </code></pre>
  
  <p>What changes will i have to make to make it working ?</p>