这个有点松鼠!
我构建了一个工作正常的存储过程。但是,当我将其放入laravel(雄辩的)迁移时,迁移会生成存储过程,但当调用它时,会给出错误1292(截断的不正确的双精度值)。在mysql workbench中,我右键单击迁移生成的存储过程,复制create语句,删除存储过程,然后从它自己的create语句中重建它。。。。还有。。。。。一切正常!
我对任何猜测都持开放态度。很明显,我希望这个存储过程是迁移的一部分,而不是需要手动构建。提前感谢:
DELIMITER $$
CREATE PROCEDURE sp_cancelTasksOnApplicationCancel(IN loanAppId INT(20))
BEGIN
SELECT loanAppId;
#SET @taskids := 0;
update tasks set task_status = 26, task_status_note = 'Application Cancelled or Denied'
where loan_app_id = loanAppId AND task_status IN (22, 23, 24) AND ( SELECT @taskids := CONCAT_WS(',', id, @taskids) );
# SELECT @taskids;
SET @cleanids = SUBSTRING(@taskids, 1, CHAR_LENGTH(@taskids) -1);
# SELECT @cleanids;
SET @pos = 0;
SET @len = 0;
WHILE LOCATE(',', @cleanids, @pos+1) > 0 DO
SET @len = LOCATE(',', @cleanids,@pos+1) - @pos;
SET @id = SUBSTRING(@cleanids, @pos, @len);
#select (@id);
IF (@id <> 0) THEN
insert into status_historys
(loan_app_id, `type`, type_recid, type_keyfield,type_status_field, type_status_date_field, type_status_note_field, type_status_userid_field, `status`, status_date, status_note, status_userid, created_at, updated_at)
values(loanAppId, 'tasks', @id, 'id', 'task status', 'tasks status datetime', 'tasks status note', 'tasks status userid', 26, now(), 'Application Cancelled or Denied', 1, now(), now());
END IF;
SET @pos = LOCATE(',', @taskids, @pos+@len) + 1;
END WHILE;
END $$
DELIMITER ;
############## 更新
问题在于以下两行。即使在命令行中,它也会对不正确的双精度值发出警告。
SET @taskids := '0';
update tasks set task_status = 22, task_status_note = 'Just Testing'
where loan_app_id = loanAppId AND task_status IN (22, 23, 24) AND ( SELECT
@taskids := CONCAT_WS(',', cast(id as char), @taskids) );
1条答案
按热度按时间yftpprvb1#
确定-主要问题是updatewhere子句中的select关键字。我相信它一直在重新声明@taskids用户变量,如果存储过程是从工作台生成的,mysql会发出警告,但是如果存储过程是通过迁移生成的,mysql就会失败。
所以正确的代码是