簡體   English   中英

MYSQL 存儲在存儲過程中的 Function

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM