2013-04-25 64 views
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); 
+0

你能解釋一下你在做什麼嗎? – Marjeta 2013-04-25 15:48:24

+0

問題是什麼? – Devart 2013-04-25 16:04:45

回答

0

你的代碼(語法)是正確的。您可能在變量和字段名稱方面存在問題,請嘗試使用不同的名稱,例如 -

CREATE DEFINER = [email protected] 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;