0
CREATE DEFINER=`root`@`localhost` PROCEDURE `bill`(subid int(10), uprice float, sd date, ed date)
BEGIN
declare numberofdays int;
declare totalprice float;

set numberofdays = datediff(ed,sd);
set totalprice= numberofdays*uprice;

insert into invoice (subscriptionid,price_perunit,numberofdays,totalprice) 
values (subid, uprice,numberofdays,totalprice);
4

1 回答 1

0

您的代码(语法)是正确的。您可能对变量和字段名称有疑问,请尝试使用不同的名称,例如 -

CREATE DEFINER = root@localhost PROCEDURE bill (subid int(10), uprice float, sd date, ed date)
BEGIN
  DECLARE var_numberofdays int;
  DECLARE var_totalprice float;

  SET var_numberofdays = DATEDIFF(ed, sd);
  SET var_totalprice = var_numberofdays * uprice;

  INSERT INTO invoice (subscriptionid, price_perunit, numberofdays, totalprice)
    VALUES (subid, uprice, var_numberofdays, var_totalprice);

  ...
END;
于 2013-04-25T16:07:22.487 回答