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 に答える