我正在尝试构建一个从表中返回值的函数
create or replace
FUNCTION TO_LOCAL_CURRENCY
(
CURR IN VARCHAR2
, VAL IN VARCHAR2
) RETURN NUMBER AS
BEGIN
RETURN (select EXRATE
from exchangerates
where CURR = 'EUR' ) * VAL;
END TO_LOCAL_CURRENCY;
基本上我输入货币和价值,它从表交换中查找汇率,并将EXRATE乘以VAL并返回结果。
我收到以下错误
Error(9,11): PLS-00103: Encountered the symbol "SELECT" when expecting one of the following: ( - + case mod new not null <an identifier> <
答案 0 :(得分:3)
SELECT
结果INTO
是一个局部变量,并返回:
create or replace
FUNCTION TO_LOCAL_CURRENCY
(
CURR IN VARCHAR2
, VAL IN VARCHAR2
) RETURN NUMBER AS
EXCHANGE_RATE NUMBER;
BEGIN
select EXRATE
into EXCHANGE_RATE
from exchangerates
where CURR = 'EUR';
return EXCHANGE_RATE * VAL;
END TO_LOCAL_CURRENCY;