我正在使用以下存储过程并在其中调用一个游标,但它返回我获取或处理的零数据该过程有什么问题?
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
我必须进行哪些更改才能使其正常工作?