我正在尝试创建一个函数,将以逗号分隔的列表作为参数传递给IN子句。
CREATE OR REPLACE EDITIONABLE FUNCTION "GET_EMPLOYEES_COUNT"(DEPT_STRING VARCHAR2) RETURN VARCHAR2 AS
count_emp VARCHAR2(10);
BEGIN
select count(*) from employees where deptname IN (DEPT_STRING);
RETURN count_emp;
END GET_EMPLOYEES_COUNT;
但是,在尝试调用以下内容时,我将变为null:
SELECT GET_EMPLOYEES_COUNT('''AGRICULTURE'',''IT''') FROM DUAL;
答案 0 :(得分:0)
尝试:
CREATE OR REPLACE FUNCTION "GET_EMPLOYEES_COUNT"(DEPT_STRING VARCHAR2)
RETURN VARCHAR2 AS
count_emp NUMBER;
BEGIN
EXECUTE IMMEDIATE q'[DECLARE q number;
begin select count(*) INTO q from employees
where deptname IN ( ]' || DEPT_STRING || q'[);
:x := q;end;]'
USING OUT count_emp;
RETURN count_emp;
END GET_EMPLOYEES_COUNT;
/