0

我已经为某些条件创建了触发器,但它通过错误。

这是触发代码。

  DELIMITER //
CREATE TRIGGER `getcrm`.`update_round_date` AFTER UPDATE ON `getcrm`.`vtiger_stockcheckcf`
 FOR EACH ROW begin
    DECLARE retribAn INTEGER DEFAULT 0; 
  DECLARE curEdate datetime;     
  DECLARE done INT DEFAULT 0;
  DECLARE curTipo CURSOR FOR
          SELECT a.*, b.*, c.* FROM vtiger_crmentity AS a, vtiger_stockcheck AS b,vtiger_stockcheckcf AS c WHERE a.crmid = b.stockcheckid AND a.crmid = c.stockcheckid AND c.cf_746 = 'Pending' AND a.setype='StockCheck';
  DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;
  OPEN curTipo;
  REPEAT
    FETCH curTipo INTO retribAn;
    IF NOT done THEN       
    set curEdate = NOW();
    IF a.createdtime = curEdate AND c.cf_746 = Pending THEN 
    INSERT INTO vtiger_cancellationcf(scheckid,cf_1150,cf_1152,cf_1154,cf_1156,cf_1151,cf_1153,cf_1155,cf_1157,cf_1158,cf_1160,cf_1162,cf_1159,
cf_1161,cf_1163,cf_1203,cf_1178,cf_1180,cf_1182,cf_1184,cf_1186,cf_1178,cf_1180,cf_1182,cf_1184,cf_1186,cf_1179,cf_1181,
cf_1183,cf_1185,cf_1187,cf_1179,cf_1181,cf_1183,cf_1185,cf_1187,cf_1164,cf_1166,cf_1168,cf_1170,cf_1165,cf_1167,cf_1169,
cf_1171,cf_1173,cf_1176,cf_1177,cf_1172,cf_1174,cf_1175,cf_1188,cf_1189,cf_1190) values ('a.crmid','"c.cf_709"','"c.cf_711"','"c.cf_713"','"c.cf_715"','"c.cf_710"','"c.cf_712"','"c.cf_714"',
'"c.cf_716"','"c.cf_717"','"c.cf_719"','"c.cf_721"','"c.cf_718"','"c.cf_720"','"c.cf_844"','"c.cf_1079"','"c.cf_736"',
'"c.cf_738"','"c.cf_740"','"c.cf_742"','"c.cf_744"','"c.cf_737"','"c.cf_739"','"c.cf_741"','"c.cf_743"','"c.cf_745"',
'"c.cf_722"','"c.cf_724"','"c.cf_726"','"c.cf_723"','"c.cf_725"','"c.cf_727"','"c.cf_729"','"c.cf_731"','"c.cf_734"',
'"c.cf_735"','"c.cf_730"','"c.cf_732"','"c.cf_733"','"b.stockcheck"','"c.cf_746"','"c.cf_1080"','"c.cf_1081"');

insert into vtiger_cancellation (cancellationid,cancellation,scheckid) values ('a.crmid',' ','c.cf_709');
insert into vtiger_crmentity (crmid,smcreatorid,smownerid,modifiedby,setype,description,createdtime,modifiedtime,viewedtime,status,version,presence,deleted,label) values ('a.crmid','a.smcreatorid','a.smownerid','a.smcreatorid','Cancellation','','curEdate','curEdate','','','0','1','0','');
delete FROM vtiger_crmentity_seq where id='a.crmid';
insert into vtiger_crmentity_seq (id)values ('a.crmid');
END IF;
END IF;
  UNTIL done END REPEAT;
  CLOSE curTipo;    
end
//
DELIMITER 

当表格发生任何变化时,这是错误的。

1328 - FETCH 变量的数量不正确

感谢提前

4

1 回答 1

0

我认为问题出在这里:FETCH curTipo INTO retribAn;您试图将完整的行获取为整数。

您应该阅读更多关于CURSORS的内容。

例子:

DECLARE a CHAR(16);
DECLARE b INT;
DECLARE cur1 CURSOR FOR SELECT id,data FROM test.t1;

OPEN cur1;

FETCH cur1 INTO a, b;
于 2013-06-18T06:45:12.747 回答