wrote a function using PostgreSQL, but I continue to get the wrong output. Can someone please help figure out what I could be doing wrong with my code? I must use PostgreSQL to write the fun
wrote a function using PostgreSQL, but I continue to get the wrong output. Can someone please help figure out what I could be doing wrong with my code? I must use PostgreSQL to write the fun
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
100%
Hi,
I wrote a function using PostgreSQL, but I continue to get the wrong output. Can someone please help figure out what I could be doing wrong with my code?
I must use PostgreSQL to write the function.
Thank you!

Transcribed Image Text:1
CREATE OR REPLACE FUNCTION Moreno_03_monthlyPayment(
2
Principal NUMERIC (12,2),
APR NUMERIC (6,0),
4
years INTEGER)
RETURNS NUMERIC
LANGUAGE plpgsql
7
AS
8.
$$
DECLARE
10
i NUMERIC(6,6)
APR/12;
11
n INTEGER = years * 12;
12
monthlyPayment NUMERIC (12,6);
13 ▼
BEGIN
SELECT Principal * (i + (i/(POWER (1+i,n))-1)) INTO monthlyPayment;
14
15
16
RETURN monthlyPayment;
17
END;
18
$$;
19
20
SELECT Moreno_03_monthlyPayment(250000.00, 0.04125, 30) AS Monthly_Payment;
Data Output
Explain
Messages
Notifications
monthly_payment
numeric
1
-248890.666791
LO

Transcribed Image Text:Problems:
1. Write a SQL function that accepts a principal mortgage amount, an annual percentage
rate (APR), and the number of years a mortgage will be paid back over. Calculate the
associated monthly mortgage payment according to the following annuity formula:
A = p[i + a)
(1+i)" –1
where:
A = Monthly Payment Amount
P = Principle (Initial) Mortgage Amount
i= APR / 12 = Monthly Interest Rate
n = years * 12 = Total Number of Payments
Be sure to specify that data types of the input arguments have enough significant digits to
account for realistic mortgage amounts (as large as in the millions of dollars) and APRS
(down to the sixth decimal place will be sufficient).
There are multiple people in the class with the same last name, so the following naming
convention must be followed exactly. You must name your function:
<LastName> <DOB DayOfMonth>_monthlyPayment
Where <LastName> is your last name and <DOB DayOfMonth> is the day of the month
you were born. This naming convention is merely meant to make the grading process
easier, so that all of the functions, procedures, and triggers have unique names.
How would I invoke this function? Below is an example of my function invocation
(call), where I am calculating the monthly payment for a mortgage with a principal
amount of $250,000, an APR of 4.125%, and a loan duration of 30 years:
SELECT Morabito_05_monthlyPayment (250000.00, 0.04125, 30);
Be sure to follow the same format that I have used for specifying the input parameters;
namely, an APR of 4.125% should be specified as 0.04125.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 1 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education