Question

In: Computer Science

ORACLE TASK 2-2 USING A FOR LOOP Create a PL/SQL block using a FOR loop to...

ORACLE

TASK 2-2 USING A FOR LOOP

Create a PL/SQL block using a FOR loop to generate a payment schedule for a donor’s pledge, which is to be paid monthly in equal increments. Values variable for the block are starting payment due date, monthly payment amount and number of total monthly payments for the pledge. The list that’s generated should display a line for each monthly payment showing payment number, date due, payment amount, and donation balance (remaining amount of pledge owed).

USING A BASIC LOOP

Accomplish the task in TASK 2-2 above by using a basic loop structure.

USING A WHILE LOOP

Accomplish the task in TASK 2-2 by using a WHILE loop structure. Instead of displaying the donation balance (remaining amount of pledge owed) on each line of output, display the total paid to date.

USING A CASE EXPRESSION

Donors can select one of three payment plans for a pledge indicated by the following codes: 0 = one-time (lump sum) payment, 1 = monthly payments over one year, and 2 = monthly payments over two years. A local business has agreed to pay matching amounts on pledge payments during the current month. A PL/SQL block is needed to identify the matching amount for a pledge payment. Create a block using input values of a payment plan code and a payment amount. Use a CASE expression to calculate the matching amount, based on the payment plan codes 0 = 25%, 1 = 50%, 2 = 100%, and other = 0. Display the calculated amount.

USING NESTED IF STATEMENTS

An organization has committed to matching pledge amounts based on the donor type and pledge amount. Donor types include I = Individual, B = Business organization, and G = Grant funds. The matching percents are to be applied as follows:

Donor Type

Pledge Amount

Matching (%)

I

$100-$249

50%

I

$250-$499

30%

I

$500 or more

20%

B

$100-$499

20%

B

$500-$999

10%

B

$1,000 or more

5%

G

$100 or more

5%

          Create a PL/SQL block using nested IF statements to accomplish the task. Input value for the block are the donor type code and the pledge amount.

Solutions

Expert Solution

Task 2-2 Using for loop

SET SERVEROUTPUT ON
DECLARE
number_of_payments NUMBER(2);    --Total # of payments
payment_num NUMBER (2);          --current payment # of total
start_date DATE;                 --payment start date
due_date DATE;                   --payment due date
monthly_payment_amt NUMBER (8,2; --monthly amt date
donation_balance NUMBER (8,2);   --remaining balance after pay
pledgeamt NUMBER (8,2)           --total amt to pay over term

BEGIN
SELECT PLEDGEAMT, PLEDGEDATE, PAYMONTHS INTO pledgeamt, start_date, num_of_payments
FROM DD_PLEDGE
WHERE IDPLEDGE = &IDPLEDGE;
monthly_payment_amt: = pledgeamt/num_of_payments;
date_due: = start_date;
donation_balance: = (pledgeamt - monthly_payment_amt);
payment_num: = 0;
FOR i IN 1..num_of_payments LOOP
payment_num: = payment_num + 1;
date_due: = add_months (date_due, 1);
DBMS_OUTPUT.PUT_LINE ('payment number:'||payment_num||'due_date:'
||date_due||'payment_amount:'||monthly_payment_amount||'balance:'
||to_char(donation_balance,'$9999.99'));
donation_balance: = donation_balance - monthly_payment_amt;
EXIT WHEN donation_balance < 0; --LOOP until condition is met
END LOOP;
END;

Related Solutions

Assignment 2- 9   USING A FOR LOOP Create a PL/SQL block using a FOR loop to...
Assignment 2- 9   USING A FOR LOOP Create a PL/SQL block using a FOR loop to generate a payment schedule for a donor’s pledge, which is to be paid monthly in equal increments. The values variable for the block is starting payment due date, monthly payment amount, and a number of total monthly payments for the pledge. The list that’s generated should display a line for each monthly payment showing payment number, date due, payment amount, and donation balance (remaining...
PL/SQL Write a PL/SQL block, using a While Loop, to calculate and print the sum of...
PL/SQL Write a PL/SQL block, using a While Loop, to calculate and print the sum of the odd integers from 10 to 120 inclusive. (Hint: 11 + 13 + 15 + . . . + 97 + 99)
Create a PL/SQL anonymous block that uses a nested loop (inner loop 1 to 15; outer...
Create a PL/SQL anonymous block that uses a nested loop (inner loop 1 to 15; outer loop 1 to 5) to perform computations using the SQL functions, ABS, EXP, SQRT, ROUND, MIN, MAX, LOG, MOD, REMAINDER and POWER The outer loop will use the functions, ABS, EXP, SQRT, ROUND to display the following messages (must be “ The absolute value of <outer loop index> is <value>” “ The value of e to the <outer loop index> power is <value>” “...
PL/SQL Write a PL/SQL block, using a Case Statement that prints a student’s letter     grade...
PL/SQL Write a PL/SQL block, using a Case Statement that prints a student’s letter     grade based on the value stored in a variable called grade. Use the ACC      grading system described in the course syllabus to create the block and set     the initial value of grade as 95. Use only one print statement and no      logical operators in your code. Assume a grade can exceed 100, but it      can’t be negative. Grade Scale: Grade Scale:...
SQL DATABASE Task 2 [10.5 marks] using the AdditionCollege database For task 2, we have provided...
SQL DATABASE Task 2 [10.5 marks] using the AdditionCollege database For task 2, we have provided you with the creation script for the AdditionCollege database. Run this script in MySQL Workbench to create the database. You should execute your query solutions to extract the necessary information. The script is based on the following schematic: Unit (Unit_code, Staff_id, [UnitName]) Staff (Staff_id, StaffName, Position, Gender) Taught_by (Unit_code, Staff_id, weekday) Student (Student_id, Student_name, Address, Gender) TuteGroup (TuteGroup_code, Unit_code, DayHrCode, Room_Nr) TuteGroup_List (TuteGroup_code, Student_id)...
Create Procedure in (PL/SQL) called Make_Account (v_first, v_last, v_email, v_errormsg) Add a new user to the...
Create Procedure in (PL/SQL) called Make_Account (v_first, v_last, v_email, v_errormsg) Add a new user to the Account table. If the new user cannot be added, return a error message. Table Account (this is the table I need to add data using PROCEDURE) Account_no (PK) Email (VARCHAR2) first (VARCHAR2) last (VARCHAR2)
Describe different roles that an insurance company might create to manage user groups. This is for ORACLE 12c: SQL
Describe different roles that an insurance company might create to manage user groups. This is for ORACLE 12c: SQL
Please implement this in Oracle sql 2.) Write a SELECT statement that answers this question: What...
Please implement this in Oracle sql 2.) Write a SELECT statement that answers this question: What is the total amount ordered for each product? Return these columns: The product name from the Products table The total amount for each product in the Order_Items (Hint: You can calculate the total amount by subtracting the discount amount from the item price and then multiplying it by the quantity) Use the ROLLUP operator to include a row that gives the grand total.
Task Description:  Create a referral letter for the following patient using Microsoft word & Full Block Style...
Task Description:  Create a referral letter for the following patient using Microsoft word & Full Block Style . Patient: Lisa Duck Dentist: Dr. Harry DDS, M.S  Address ... Radiograph Findings: Impacted third molars, mild bone loss around max and mandibular molars. Fractured amalgam on the mandibular left first molar Oral Examination Findings: Confirmed mild periodontitis, fractured amalgam, Class III Mobility on 37 electrical shock like pain that radiates to his lower lip when tooth clenched.
Database: Configure Oracle Net manager: Create the directory E:\oracle\net to be used by Oracle Net configuration...
Database: Configure Oracle Net manager: Create the directory E:\oracle\net to be used by Oracle Net configuration files and then set TNS_ADMIN variable to point to this. To set this variable you will need to open regedit.exe (the “Registry Editor”) first. Next, you will create and set the key TNS_ADMIN as a string variable in the registry in the Oracle Home branch. This will likely be: HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_OraDB12Home1 How to set TNS_ADMIN variable correctly.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT