我正在尝试创建一个FUNCTION
来获取所输入参数的位置,当我测试该函数时它输入的ID不起作用它会给出错误ORA-00923
create or replace FUNCTION GET_LOCATION (l_con_id in NUMBER)
RETURN VARCHAR2
AS
LOCATION VARCHAR2(30);
BEGIN
SELECT LOCATION
INTO LOCATION
FROM LDS_CONSULTANT
WHERE CONSULTANT_ID = l_con_id;
RETURN LOCATION;
END;
答案 0 :(得分:1)
这是我的建议。
首先,一个简单的测试用例:
SQL> create table lds_consultant
2 (consultant_id number,
3 location varchar2(30));
Table created.
SQL> insert into lds_consultant
2 select 1, 'New York' from dual union
3 select 2, 'London' from dual;
2 rows created.
功能:
SQL> create or replace function get_location
2 (par_consultant_id in lds_consultant.consultant_id%type)
3 return lds_consultant.location%type
4 is
5 l_location lds_consultant.location%type;
6 begin
7 select max(l.location)
8 into l_location
9 from lds_consultant l
10 where l.consultant_id = par_consultant_id;
11 return l_location;
12 end;
13 /
Function created.
最后,您调用它的方式:标准方式选择......来自双:
SQL> select get_location(2) result_1,
2 get_location(-1) result_2
3 from dual;
RESULT_1 RESULT_2
------------------------------ ------------------------------
London
SQL>
<强> [编辑] 强>
由于Apex使用PL / SQL,您必须声明一个局部变量并将该函数的结果放入其中。像这样:
declare
l_result lds_consultant.location%type;
begin
l_result := get_location(:P1_CONSULTANT_ID);
end;
或者,如果是报告,则将其作为
包含在SELECT语句中select l.consultant_id,
l.consultant_name,
get_location(l.consultant_id) location
from lds_consultant l
order by l.consultant_name;
顺便说一句,从双中选择适用于Oracle中的任何地方(包括Apex)。