Oracle查询:
CREATE OR REPLACE FUNCTION case_filter(p_account_id IN DOUBLE PRECISION
, p_case_type_id IN DOUBLE PRECISION
, p_activity IN VARCHAR(4000) DEFAULT NULL
, p_step IN VARCHAR(4000) DEFAULT NULL
, p_char_fld_obj IN ct_char_obj DEFAULT NULL
, p_num_fld_obj IN ct_num_obj DEFAULT NULL
, p_from_date_fld_obj IN ct_date_obj DEFAULT NULL
, p_to_date_fld_obj IN ct_date_obj DEFAULT NULL)
RETURNS number_tab_t
AS
$BODY$
DECLARE
l_case_ids number_tab_t;
l_case_ids_local number_tab_t;
BEGIN
select array_agg(ccase.case_id) INTO l_case_ids
from ct_case ccase
INNER JOIN ct_case_type casetype
on (casetype.case_type_id = ccase.case_type_id and casetype.account_id = p_account_id)
WHERE ccase.case_type_id = coalesce(p_case_type_id, ccase.case_type_id);
l_case_ids_local := l_case_ids;
IF p_employee IS NULL THEN
RETURN SET(l_case_ids);
ELSE
SELECT DISTINCT array_agg(case_id) INTO l_case_ids
FROM (SELECT case_id
FROM employee_data ed
INNER JOIN ct_case c
ON (c.employee_id = ed.employee_id AND ed.account_id = p_account_id)
INNER JOIN l_case_ids_local () bc
ON (c.case_id = bc.column_value)
WHERE REGEXP_REPLACE(UPPER(ed.last_name || ',' || ed.first_name || ed.middle_name), '[^A-Z,]', '') LIKE '%'|| replace(REGEXP_REPLACE(upper(p_employee), '[^A-Z,]',''),',','%,')|| '%') as re;
END IF;
RETURN SET(l_case_ids);
END;
$BODY$
LANGUAGE plpgsql;
由于我们正在将该查询迁移到PostgreSQL,所以我们遇到了表函数的问题。 PostgreSQL中不直接支持table(整数的集合),PostgreSQL中还有其他选择吗? 谢谢。
答案 0 :(得分:0)
只需删除TABLE
运算符并使用l_case_ids_local()
INNER JOIN l_case_ids_local() bc
ON (c.case_id = bc.col) -- use the column name as
-- defined in the function.