在postgres函数内部具有“递归”

问题描述 投票:0回答:1

我必须完成此代码段

begin transaction;
create or replace function amort(amount decimal, periodiquepayment decimal, interet decimal) 
returns table (periodereq decimal, payreq decimal, restreq decimal) as 
$$
begin
     [...]
end 
$$
language 'plpgsql';
select * from amort(50000.00,500.00, 0.10);
rollback;

以及[...]的位置,我应该实施递归WITH以计算定期付款的值。但是我没有尝试过。我什至无法获得正确的语法来正确地使用:(第一个参数是总金额,第二个参数是定期付款,第三个参数是每次定期付款后应用于总金额的利息

postgresql recursive-query
1个回答
0
投票
根据您的描述,改为使用SQL函数会更简单,更好:

CREATE FUNCTION amort(amount decimal, periodiquepayment decimal, interet decimal) RETURNS TABLE (periodereq decimal, payreq decimal, restreq decimal) LANGUAGE sql AS $$WITH ... AS (...) SELECT ...$$;

© www.soinside.com 2019 - 2024. All rights reserved.