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),我的疑问是如何在另一个查询中传递返回值。在这里,我在货币表中传递 publisher_currency 值。它显示错误,因为结果包含多于一行。

4

1 回答 1

0

抛出此错误是因为您的请求返回了不止一行:

select base_value into convert_base from currencys where base_currency='publisher_currency';

convert_base并且不可能在变量中插入多个值

于 2013-02-22T15:05:51.470 回答