我的MySQL不工作,值似乎为0

时间:2015-01-13 12:12:14

标签: mysql database triggers

不知怎的,我的MySQL触发器无效。当它转移到另一个表(作为一种System.out.println)时,new.itemID似乎是0,尽管这是一个auto_increment。 然而,vZeroes也是0

DROP TRIGGER IF EXISTS `insertItemAlterEAN`;
DELIMITER //
CREATE TRIGGER `insertItemAlterEAN` before INSERT ON `item`
FOR EACH ROW BEGIN
    declare vEANasString char(13);
    declare vIDasString char(13);
    declare vZeroeschar(13);
    declare vIterator int;

    SET vIDasString = CAST(new.itemID as char(13));
    SET vIterator = 13 - char_length(vIDasString) - 3;
    SET vZeroes= '';
    while vIterator > 0 DO 
        SET vZeroes= vZeroes+ '0';
        SET vIterator = vIterator - 1;
    END WHILE;
    insert into tmptable (descr, value) values(cast(vIDasString as unsigned), vZeroes);
    SET vEANasString = CONCAT('400', vZeroes, vIDasString);
    set new.EAN = CAST(vEANasString as unsigned);
END
//
DELIMITER ;

请帮忙!我迷失了

0 个答案:

没有答案