本文介绍了在单个参数中传递多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过在单个参数上传递多个值来调用函数,如下所示:

I want to call a function by passing multiple values on single parameter, like this:

SELECT * FROM jobTitle('270,378');

这是我的职责.

CREATE OR REPLACE FUNCTION test(int)
RETURNS TABLE (job_id int, job_reference int, job_job_title text
                                            , job_status text) AS
$$
BEGIN
RETURN QUERY
select jobs.id,jobs.reference, jobs.job_title,
       ltrim(substring(jobs.status,3,char_length(jobs.status))) as status
FROM jobs ,company c
WHERE jobs."DeleteFlag" = '0'
and c.id= jobs.id and c.DeleteFlag = '0' and c.active = '1' 
and (jobs.id = $1 or -1 = $1)
order by jobs.job_title;
END;
$$ LANGUAGE plpgsql;

有人可以提供语法帮助吗?甚至提供示例代码?

Can someone help with the syntax? Or even provide sample code?

推荐答案

类似于已提供@mu VARIADIC 是您的朋友.一个更重要的细节:

Like @mu already provided, VARIADIC is your friend. One more important detail:

还可以使用具有数组类型的VARIADIC参数直接调用函数.在函数调用中添加关键字VARIADIC:

You can also call a function using a VARIADIC parameter with an array type directly. Add the key word VARIADIC in the function call:

SELECT * FROM  f_test(VARIADIC '{1,2,3}'::int[]);

等效于:

SELECT * FROM  f_test(1,2,3);

其他建议

09-22 05:00