在使用存储过程插入mysql期间,将两列相乘并将结果放入第三列

时间:2013-03-24 08:52:09

标签: mysql database stored-procedures insert

我想做这样的事情:

Quantity   Price    Payment
1           12      12.00

这是我的代码:

CREATE DEFINER=`root`@`localhost` 
PROCEDURE `insertproducts`
(
    pname varchar(50), 
    pdesc varchar(50),
    psupp varchar(50),
    pdate date,
    pquant int,
    pprice double
)
begin
insert into products
(
    prodname,
    proddescription,
    prodsupplier,
    proddate,
    prodquantity,
    prodprice,
    prodpayment
) 
values 
(
    pname,
    pdesc,
    psupp,
    pdate,
    pquant,
    pprice,
    ppayment
) 
set prodpayment = pprice * prodquantity;
end

这不起作用,任何想法?

1 个答案:

答案 0 :(得分:3)

什么是ppayment?您可以直接乘以参数

insert into products
(
    prodname, 
    proddescription, 
    prodsupplier, 
    proddate, 
    prodquantity, 
    prodprice, 
    prodpayment
) 
values 
(
    pname, 
    pdesc, 
    psupp, 
    pdate, 
    pquant, 
    pprice, 
    pprice*prodquantity
)