Function for Postgresql

后端 未结 1 1694
礼貌的吻别
礼貌的吻别 2021-01-26 16:13

On this website I saw a function, that I would like to use with postgresql:

https://raresql.com/2013/05/16/sql-server-excel-financial-functions-pmt/

Here is the

相关标签:
1条回答
  • 2021-01-26 16:34
    CREATE OR REPLACE FUNCTION UDF_PMT (
     InterestRate  NUMERIC(18,8),
     Nper          INTEGER,
     Pv            NUMERIC(18,4),
     Fv            NUMERIC(18,4),
     Typ           INTEGER
    )
    RETURNS NUMERIC(18,2)
    AS $$
        SELECT round(
            CASE
            WHEN Typ = 0 THEN 
                (InterestRate / 100) /
                (Power(1 + InterestRate / 100, Nper) - 1) *
                (Pv * Power(1 + InterestRate / 100, Nper) + Fv)
            WHEN Typ = 1 THEN
                (InterestRate / 100) /
                (Power(1 + InterestRate / 100, Nper) - 1) *
                (Pv * Power(1 + InterestRate / 100, Nper) + Fv) /
                (1 + InterestRate / 100)
            END, 2)
    $$ LANGUAGE SQL;
    
    0 讨论(0)
提交回复
热议问题