[英]MYSQL stored Function in stored procedure
我希望它根據兩列值計算總價。 第一個是藝術家價格第二個是約會 sessionlenght
約會有一個藝術家的外鍵 - 所以他們連接到藝術家主鍵(藝術家 CPR)
DELIMITER // CREATE FUNCTION AppointmentPrice( price Int(10), SessionLenght int(10) ) RETURNS int(100) DETERMINISTIC BEGIN SELECT artist.price, appointment.sessionlenght FROM ((Appointment INNER JOIN Artist on Appointment.Artist_CPR=Artist.CPR)) DECLARE AppointmentPrice int(100); set AppointmentPrice = Artist.price*Appointment.SessionLenght; -- return the AppointmentPrice RETURN (AppointmentPrice); END // DELIMITER;
現在的問題是它突出顯示了 DECLARE 並說它在 position 無效。 在我想將它放入存儲過程之后,當我調用該過程時,我得到所有約會的所有總價
我的桌子:
它是虛擬數據。
DELIMITER //
CREATE FUNCTION AppointmentPrice(
price Int(10),
SessionLenght int(10)
)
RETURNS int(100)
DETERMINISTIC
BEGIN
DECLARE AppointmentPrice int(100);
DECLARE artist_price int(100); // NOT:= set datatype accordingly to query result for this column artist.price , for now I have declare it as int
DECLARE Appointment_SessionLenght int(100); // NOT:= set datatype accordingly to query result for this column appointment.sessionlenght, for now I have declare it as int
SELECT artist.price, appointment.sessionlenght into artist_price, Appointment_SessionLenght FROM ((Appointment INNER JOIN Artist on Appointment.Artist_CPR=Artist.CPR))
set AppointmentPrice = (artist_price * Appointment_SessionLenght);
-- return the AppointmentPrice
RETURN (AppointmentPrice);
END //
DELIMITER ;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.