0
這裏我使用mysql函數做了貨幣轉換。請在下面,如何在函數查詢中設置返回值
CREATE FUNCTION anycurrency_inr(book_id INT,pub_id INT) RETURNS DOUBLE
DETERMINISTIC
BEGIN
DECLARE publisher_currency VARCHAR(60);
DECLARE org_amount DOUBLE;
DECLARE inr_amount DOUBLE;
DECLARE convert_base DOUBLE;
DECLARE convert_current DOUBLE;
select publishers.currency into publisher_currency from publishers,books where publishers.user_id=pub_id and books.id=book_id;
select publisher_currency into org_amount from books where user_id=pub_id;
IF (publisher_currency ='inr_price') THEN
set inr_amount=org_amount;
ELSE
select base_value into convert_base from currencys where base_currency='publisher_currency';
select current_value into convert_current from currencys where base_currency='publisher_currency';
set inr_amount=org_amount * (convert_current/convert_base);
RETURN inr_amount;
END IF;
END
出版商表上方的返回幣值爲publisher_currency可能爲(inr_price或doller_price或pound_price或euro_price)和我的疑問是如何在另一個查詢傳遞返回值。這裏我傳遞了currencys表中的publisher_currency值。它顯示錯誤,因爲Result包含多行。
在這裏,我返回inr_amount only.It有可能上面的查詢將作爲base_currency ='euro_price' – Sundar 2013-02-22 15:09:41
base_value只返回一個值,當我通過(inr_price或doller_price或euro_price或pound_price) – Sundar 2013-02-22 15:13:40