我在创建具有以下定义的函数时遇到问题:
CREATE OR REPLACE FUNCTION COPY_ACTIONS_V1_TEST(iActionMasterIdList IN text)
RETURNS TEXT AS $$
DECLARE
vRequestedId ACTIONS.ACTION_ID%TYPE;
result_aid_list TEXT;
cur_action CURSOR FOR
select act.ACTION_ID
FROM ACTIONS act
WHERE 1=1
and act.action_id IN iActionMasterIdList;
BEGIN
OPEN cur_action;
LOOP
FETCH cur_action INTO vActionMasterId;
if not FOUND THEN
return result_aid_list;
end if;
END LOOP;
CLOSE cur_action;
END;
$$ LANGUAGE plpgsql;
我想将文本变量作为"123124126"传递给此函数,并在表中搜索此ID。我尝试了很多选择,比如:
- act.action_id=任意(字符串to_array(iActionMasterIdList((
- act.action_id=任意("{"| | iActionMasterIdList | |"}"(
但什么都不管用。每个都会抛出不同的错误。我不是postgres方面的专家,你能给我建议吗?
谢谢
string_to_array
-以文本类型返回数组元素。如果action_id
是整数,则可以使用强制转换类型。示例:
and act.action_id::text = any(string_to_array(iActionMasterIdList, ','))