在函数空白结果中选择语句

时间:2015-12-02 13:00:26

标签: postgresql function plpgsql

我正在使用Postgresql并尝试在函数中调用select语句。目前,电话会给我零结果

CREATE OR REPLACE FUNCTION f_all_male_borrowers
(
OUT p_given_names varchar(60), 
OUT p_family_name varchar(60), 
OUT p_gender_code integer
)


RETURNS SETOF record as $body$
declare body text;

BEGIN
SELECT into p_given_names,p_family_name, p_gender_code
borrower.given_names, borrower.family_name, gender.gender_code

FROM BORROWER

INNER join gender on borrower.gender_code=gender.gender_code

WHERE borrower.gender_code = '1';

RETURN ;

END;
$body$ LANGUAGE plpgsql;

致电功能:

select * from f_all_male_borrowers()

缺少什么,或者我在这里做错了什么?

谢谢

1 个答案:

答案 0 :(得分:0)

CREATE OR REPLACE FUNCTION f_all_male_borrowers
(
OUT p_given_names varchar(60), 
OUT p_family_name varchar(60), 
OUT p_gender_code integer
)
RETURNS SETOF record as 
$body$
SELECT into p_given_names,p_family_name, p_gender_code
borrower.given_names, borrower.family_name, gender.gender_code
FROM BORROWER
INNER join gender on borrower.gender_code=gender.gender_code
WHERE borrower.gender_code = '1';
$body$
LANGUAGE sql VOLATILE
  COST 100
  ROWS 1000;
ALTER FUNCTION f_all_male_borrowers()
  OWNER TO postgres;

尝试此操作,然后致电:

select * from f_all_male_borrowers();

在此之前,您需要检查您的查询是否有结果!!

创建功能后:

Got to Functions->Right click your function(ie,f_all_male_borrowers())-> Scripts->Select Script ->Then run it.

如果它返回结果,那么您的程序是正确的。