0

当前出现错误

20:45:54 call book_rental(1, 5, 2, 50.00, 2, 2, 5.00, 3, 4, 2.00, 4, 2, 10.00, '现金', '2016-01-01', '2016-01 -05') 错误代码:1292。不正确的日期时间值:第 1 行的列 'date' 的 '2014' 0.265 秒

这是代码。请帮忙!

DROP PROCEDURE IF EXISTS book_rental;

DELIMITER //
CREATE PROCEDURE book_rental(customer_id_param MEDIUMINT, item1_id TINYINT, item1_qty SMALLINT, item1_price DECIMAL(9,2), item2_id TINYINT, item2_qty SMALLINT, item2_price DECIMAL(9,2), item3_id TINYINT, item3_qty SMALLINT, item3_price DECIMAL(9,2), item4_id TINYINT, item4_qty SMALLINT, item4_price DECIMAL(9,2), payment_type ENUM('cash', 'check', 'credit'), pickup_date DATE, return_date DATE)
BEGIN
    DECLARE invdate DATE;
    SET invdate := pickup_date;
    SET @item1inv = CONCAT('UPDATE running_inventory SET `', item1_id, '` = `', item1_id, '` - ', item1_qty, ' WHERE date = ', invdate);
    SET @item2inv = CONCAT('UPDATE running_inventory SET `', item2_id, '` = `', item2_id, '` - ', item2_qty, ' WHERE date = ', invdate);
    SET @item3inv = CONCAT('UPDATE running_inventory SET `', item3_id, '` = `', item3_id, '` - ', item3_qty, ' WHERE date = ', invdate);
    SET @item4inv = CONCAT('UPDATE running_inventory SET `', item4_id, '` = `', item4_id, '` - ', item4_qty, ' WHERE date = ', invdate);

    PREPARE upd1 FROM @item1inv;
    PREPARE upd2 FROM @item2inv;
    PREPARE upd3 FROM @item3inv;
    PREPARE upd4 FROM @item4inv;

    INSERT INTO invoices (customer_id, invoice_date, invoice_total, payment_type) VALUES (customer_id_param, NOW(), 1.07 * ((item1_qty * item1_price) + (item2_qty * item2_price) + (item3_qty * item3_price) + (item4_qty * item4_price)), payment_type);
    INSERT INTO invoice_line_items (invoice_sequence, item_id, item_qty, price_per) VALUES (1, item1_id, item1_qty, item1_price);
    INSERT INTO invoice_line_items (invoice_sequence, item_id, item_qty, price_per) VALUES (2, item2_id, item2_qty, item2_price);
    INSERT INTO invoice_line_items (invoice_sequence, item_id, item_qty, price_per) VALUES (3, item3_id, item3_qty, item3_price);
    INSERT INTO invoice_line_items (invoice_sequence, item_id, item_qty, price_per) VALUES (4, item4_id, item4_qty, item4_price);

    REPEAT
        EXECUTE upd1;
        EXECUTE upd2;
        EXECUTE upd3;
        EXECUTE upd4;
        SET invdate = DATE_ADD(invdate, INTERVAL 1 DAY);
    UNTIL invdate = DATE_SUB(return_date, INTERVAL 1 DAY)
    END REPEAT;

    DEALLOCATE PREPARE upd1;
    DEALLOCATE PREPARE upd2;
    DEALLOCATE PREPARE upd3;
    DEALLOCATE PREPARE upd4;
END//
4

1 回答 1

0

在将值传递给准备好的语句时,您应该使用参数。但是,如果不是,日期需要用单引号括起来。所以,而不是:

SET @item1inv = CONCAT('UPDATE running_inventory SET `', item1_id, '` = `', item1_id, '` - ', item1_qty, ' WHERE date = ', invdate);

它应该是:

SET @item1inv = CONCAT('UPDATE running_inventory SET `', item1_id, '` = `', item1_id, '` - ', item1_qty, ' WHERE date = ''', invdate, '''');
于 2016-05-04T01:53:32.193 回答