gpt4 book ai didi

postgresql - 存储过程给出错误 : query has no destination for result data

转载 作者:行者123 更新时间:2023-12-03 09:24:37 24 4
gpt4 key购买 nike

我有一个存储过程,如下所示。我总是认为最后一次选择的结果会自动返回,但是我收到了这个错误,我不知道为什么,有人可以启发我吗?

    CREATE OR REPLACE FUNCTION pGetPlans() RETURNS TABLE (
title varchar(16),
full_cost money,
subtitle varchar(128),
blurb varchar(128),
details varchar(128)[],
final_str text)
AS $$
DECLARE
full_cost tplan.cost%TYPE;
current_cost tplan.cost%TYPE;
amount_saved tplan.cost%TYPE;
percent_saved float;
monthly_cost tplan.cost%TYPE;
one_month_cost tplan.cost%TYPE;
you_save tplan.cost%TYPE;

BEGIN
select
cost
into
one_month_cost
from
tplan
where
is_base = true;

select
p.title,
p.cost,
p.subtitle,
p.blurb,
p.details,
'1 Month Cost is: ' || one_month_cost::text as final_str
from
tplan p
where
p.status = 'A';
END;
$$ LANGUAGE plpgsql;

谢谢克鲁兹

最佳答案

I always though that the last select's result would be returned automatically

这只适用于使用 sql 语言编写的函数,而不是 plpgsql 和其他语言。

Documentation引用:

SQL functions execute an arbitrary list of SQL statements, returning the result of the last query in the list.

使用RETURN QUERY SELECT...作为最后一条指令,在plpgsql中实现相同的效果。

关于postgresql - 存储过程给出错误 : query has no destination for result data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23338542/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com