Question

In: Computer Science

Using SQL Developer Question 1 Create a block to retrieve and display pledge and payment information...

Using SQL Developer

Question 1

Create a block to retrieve and display pledge and payment information for a specific donor. For each pledge payment from the donor, display the pledge ID, pledge amount, number of monthly payments, payment date, and payment amount. The list should be sorted by pledge ID and then by payment date. For the first payment made for each pledge, display “first payment” on that output row.

Question 2

Redo question 1, but use a different cursor form to perform the same task.

---Data---

DROP TABLE dd_donor CASCADE CONSTRAINTS;
DROP TABLE dd_project CASCADE CONSTRAINTS;
DROP TABLE dd_status CASCADE CONSTRAINTS;
DROP TABLE dd_pledge CASCADE CONSTRAINTS;
DROP TABLE dd_payment CASCADE CONSTRAINTS;
CREATE TABLE DD_Donor (
   idDonor number(4),
   Firstname varchar2(15),
   Lastname varchar2(30),
Typecode CHAR(1),
   Street varchar2(40),
   City varchar2(20),
   State char(2),
   Zip varchar2(9),
   Phone varchar2(10),
   Fax varchar2(10),
   Email varchar2(25),
News char(1),
   dtentered date DEFAULT SYSDATE,
   CONSTRAINT donor_id_pk PRIMARY KEY(idDonor) );
CREATE TABLE DD_Project (
idProj number(6),
Projname varchar2(60),
Projstartdate DATE,
Projenddate DATE,
Projfundgoal number(12,2),
ProjCoord varchar2(20),
CONSTRAINT project_id_pk PRIMARY KEY(idProj),
CONSTRAINT project_name_uk UNIQUE (Projname) );
CREATE TABLE DD_Status (
idStatus number(2),
Statusdesc varchar2(15),
CONSTRAINT status_id_pk PRIMARY KEY(idStatus) );   
CREATE TABLE DD_Pledge (
idPledge number(5),
idDonor number(4),
Pledgedate DATE,
Pledgeamt number(8,2),
idProj number(5),
idStatus number(2),
Writeoff number(8,2),
paymonths number(3),
Campaign number(4),
Firstpledge char(1),
CONSTRAINT pledge_id_pk PRIMARY KEY(idPledge),
CONSTRAINT pledge_idDonor_fk FOREIGN KEY (idDonor)
REFERENCES dd_donor (idDonor),
CONSTRAINT pledge_idProj_fk FOREIGN KEY (idProj)
REFERENCES dd_project (idProj),
CONSTRAINT pledge_idStatus_fk FOREIGN KEY (idStatus)
REFERENCES dd_status (idStatus));   
CREATE TABLE DD_Payment (
idPay number(6),
idPledge number(5),
Payamt number(8,2),
Paydate DATE,
Paymethod char(2),
CONSTRAINT payment_id_pk PRIMARY KEY(idPay),
CONSTRAINT pay_idpledge_fk FOREIGN KEY (idPledge)
REFERENCES dd_pledge (idPledge) );   
INSERT INTO dd_donor
VALUES (301, 'Mary', 'Treanor', 'I','243 main St.', 'Norfolk', 'VA','23510',NULL,NULL,'[email protected]','Y','01-SEP-2012');
INSERT INTO dd_donor
VALUES (302, 'Patrick', 'Lee', 'I','11 Hooper St.', 'Norfolk', 'VA','23510','7572115445',NULL,'[email protected]','N','09-SEP-2012');
INSERT INTO dd_donor
VALUES (303, 'Terry', 'Venor', 'I','556 Loop Lane.', 'Chesapeake', 'VA','23320',NULL,NULL,'[email protected]','Y','18-SEP-2012');
INSERT INTO dd_donor
VALUES (304, 'Sherry', 'Pane', 'I','Center Blvd.', 'Virginia Beach', 'VA','23455',NULL,NULL,'[email protected]','Y','21-SEP-2012');
INSERT INTO dd_donor
VALUES (305, 'Thomas', 'Sheer', 'I','66 Train St.', 'Chesapeake', 'VA','23322','7579390022',NULL,'[email protected]','Y','01-MAR-2013');
INSERT INTO dd_donor
VALUES (306, NULL, 'Coastal Developers', 'B','3667 Shore Dr.', 'Virginia Beach', 'VA','23450','8889220004',NULL,'[email protected]','Y','30-SEP-2012');
INSERT INTO dd_donor
VALUES (307, NULL, 'VA Community Org', 'G','689 Bush Dr.', 'Norfolk', 'VA','23513','7578337467','7578337468','[email protected]','Y','03-OCT-2012');
INSERT INTO dd_donor
VALUES (308, 'Betty', 'Konklin', 'I','11 Shark Ln.', 'Virginia Beach', 'VA','23455','7574550087',NULL,'[email protected]','N','04-OCT-2012');
INSERT INTO dd_donor
VALUES (309, 'Jim', 'Tapp', 'I','200 Pine Tree Blvd.', 'Chesapeake', 'VA','23320','',NULL,'','N','08-OCT-2012');
INSERT INTO dd_donor
VALUES (310, NULL, 'Unique Dezigns', 'B','Connect Circle Unit 12', 'Chesapeake', 'VA','23320','7574442121',NULL,'[email protected]','Y','11-SEP-2012');
INSERT INTO dd_project
VALUES (500,'Elders Assistance League', '01-SEP-2012','31-OCT-2012',15000,'Shawn Hasee');
INSERT INTO dd_project
VALUES (501,'Community food pantry #21 freezer equipment', '01-OCT-2012','31-DEC-2012',65000,'Shawn Hasee');
INSERT INTO dd_project
VALUES (502,'Lang Scholarship Fund', '01-JAN-2013','01-NOV-2013',100000,'Traci Brown');
INSERT INTO dd_project
VALUES (503,'Animal shelter Vet Connect Program', '01-DEC-2012','30-MAR-2013',25000,'Traci Brown');
INSERT INTO dd_project
VALUES (504,'Shelter Share Project 2013', '01-FEB-2013','31-JUL-2013',35000,'Traci Brown');
INSERT INTO dd_status
VALUES (10,'Open');
INSERT INTO dd_status
VALUES (20,'Complete');
INSERT INTO dd_status
VALUES (30,'Overdue');
INSERT INTO dd_status
VALUES (40,'Closed');
INSERT INTO dd_status
VALUES (50,'Hold');
INSERT INTO dd_pledge
VALUES (100,303,'18-SEP-2012',80,500,20,NULL,0,738,'Y');
INSERT INTO dd_pledge
VALUES (101,304,'21-SEP-2012',35,500,20,NULL,0,738,'Y');
INSERT INTO dd_pledge
VALUES (102,310,'01-OCT-2012',500,501,20,NULL,0,749,'Y');
INSERT INTO dd_pledge
VALUES (103,307,'03-OCT-2012',2000,501,20,NULL,0,749,'N');
INSERT INTO dd_pledge
VALUES (104,308,'04-OCT-2012',240,501,10,NULL,12,749,'Y');
INSERT INTO dd_pledge
VALUES (105,309,'08-OCT-2012',120,501,10,NULL,12,749,'Y');
INSERT INTO dd_pledge
VALUES (106,301,'12-OCT-2012',75,500,20,NULL,0,738,'N');
INSERT INTO dd_pledge
VALUES (107,302,'15-OCT-2012',1200,501,10,NULL,24,749,'Y');
INSERT INTO dd_pledge
VALUES (108,308,'20-JAN-2013',480,503,10,NULL,24,790,'N');
INSERT INTO dd_pledge
VALUES (109,301,'01-FEB-2013',360,503,10,NULL,12,790,'N');
INSERT INTO dd_pledge
VALUES (110,303,'01-MAR-2013',300,504,10,NULL,12,756,'N');
INSERT INTO dd_pledge
VALUES (111,306,'01-MAR-2013',1500,504,20,NULL,0,756,'Y');
INSERT INTO dd_pledge
VALUES (112,309,'16-MAR-2013',240,504,10,NULL,12,756,'N');
INSERT INTO dd_payment
VALUES (1425,100,80,'18-SEP-2012','CC');
INSERT INTO dd_payment
VALUES (1426,101,35,'21-SEP-2012','DC');
INSERT INTO dd_payment
VALUES (1427,102,500,'01-OCT-2012','CH');
INSERT INTO dd_payment
VALUES (1428,103,2000,'03-OCT-2012','CH');
INSERT INTO dd_payment
VALUES (1429,106,75,'12-OCT-2012','CC');
INSERT INTO dd_payment
VALUES (1430,104,20,'01-NOV-2012','CC');
INSERT INTO dd_payment
VALUES (1431,105,10,'01-NOV-2012','CC');
INSERT INTO dd_payment
VALUES (1432,107,50,'01-NOV-2012','CC');
INSERT INTO dd_payment
VALUES (1433,104,20,'01-DEC-2012','CC');
INSERT INTO dd_payment
VALUES (1434,105,10,'01-DEC-2012','CC');
INSERT INTO dd_payment
VALUES (1435,107,50,'01-DEC-2012','CC');
INSERT INTO dd_payment
VALUES (1436,104,20,'01-JAN-2013','CC');
INSERT INTO dd_payment
VALUES (1437,105,10,'01-JAN-2013','CC');
INSERT INTO dd_payment
VALUES (1438,107,50,'01-JAN-2013','CC');
INSERT INTO dd_payment
VALUES (1439,104,20,'01-FEB-2013','CC');
INSERT INTO dd_payment
VALUES (1440,105,10,'01-FEB-2013','CC');
INSERT INTO dd_payment
VALUES (1441,107,50,'01-FEB-2013','CC');
INSERT INTO dd_payment
VALUES (1442,108,20,'01-FEB-2013','CC');
INSERT INTO dd_payment
VALUES (1443,109,30,'01-FEB-2013','CC');
INSERT INTO dd_payment
VALUES (1444,104,20,'01-MAR-2013','CC');
INSERT INTO dd_payment
VALUES (1445,105,10,'01-MAR-2013','CC');
INSERT INTO dd_payment
VALUES (1446,107,50,'01-MAR-2013','CC');
INSERT INTO dd_payment
VALUES (1447,108,20,'01-MAR-2013','CC');
INSERT INTO dd_payment
VALUES (1448,109,30,'01-MAR-2013','CC');
INSERT INTO dd_payment
VALUES (1449,110,25,'01-MAR-2013','CC');
INSERT INTO dd_payment
VALUES (1450,111,1500,'01-MAR-2013','CH');
INSERT INTO dd_payment
VALUES (1451,104,20,'01-APR-2013','CC');
INSERT INTO dd_payment
VALUES (1452,105,10,'01-APR-2013','CC');
INSERT INTO dd_payment
VALUES (1453,107,50,'01-APR-2013','CC');
INSERT INTO dd_payment
VALUES (1454,108,20,'01-APR-2013','CC');
INSERT INTO dd_payment
VALUES (1455,109,30,'01-APR-2013','CC');
INSERT INTO dd_payment
VALUES (1456,110,25,'01-APR-2013','CC');
INSERT INTO dd_payment
VALUES (1457,112,20,'01-APR-2013','CC');
INSERT INTO dd_payment
VALUES (1458,104,20,'01-MAY-2013','CC');
INSERT INTO dd_payment
VALUES (1459,105,10,'01-MAY-2013','CC');
INSERT INTO dd_payment
VALUES (1460,107,50,'01-MAY-2013','CC');
INSERT INTO dd_payment
VALUES (1461,108,20,'01-MAY-2013','CC');
INSERT INTO dd_payment
VALUES (1462,109,30,'01-MAY-2013','CC');
INSERT INTO dd_payment
VALUES (1463,110,25,'01-MAY-2013','CC');
INSERT INTO dd_payment
VALUES (1464,112,20,'01-MAY-2013','CC');
COMMIT;

Solutions

Expert Solution

Question 1: SOLUTION

SELECT DD_Pledge.idPledge,Pledgeamt,paymonths,Paydate,Payamt,Firstpledge,
CASE WHEN Firstpledge='Y' THEN 'First payment'
END AS PAYMENTDETAILS
from DD_Pledge,DD_Payment
where DD_Payment.idPledge=DD_Pledge.idPledge
order by DD_Pledge.idPledge,Paydate;

Question 2: SOLUTION

SET NOCOUNT ON
DECLARE @idPledge number
DECLARE @Pledgeamt number
DECLARE @paymonths number
DECLARE @Paydate date
DECLARE @Payamt number
DECLARE @Firstpledge char(1)
 DECLARE cur_emp CURSOR
STATIC FOR 
SELECT DD_Pledge.idPledge,Pledgeamt,paymonths,Paydate,Payamt,Firstpledge,
CASE WHEN Firstpledge='Y' THEN 'First payment'
END AS PAYMENTDETAIS
from DD_Pledge,DD_Payment
where DD_Payment.idPledge=DD_Pledge.idPledge
order by DD_Pledge.idPledge,Paydate;
OPEN cur_emp
IF @@CURSOR_ROWS > 0
 BEGIN 
 FETCH NEXT FROM cur_emp INTO  @idPledge,@Pledgeamt,@paymonths,@Paydate,@Payamt,@Firstpledge
 WHILE @@Fetch_status = 0
 BEGIN
 PRINT ''+ convert(varchar(20),@idPledge)+' ,'+convert(varchar(20),@Pledgeamt)+ ', '+convert(varchar(20),@paymonths)+','+convert(varchar(20),@Paydate)+', '
 convert(varchar(20),@Payamt)+', '+@Firstpledge
 FETCH NEXT FROM cur_emp INTO @idPledge,@Pledgeamt,@paymonths,@Paydate,@Payamt,@Firstpledge
 END
END
CLOSE cur_emp
DEALLOCATE cur_emp
SET NOCOUNT OFF 

Thank you! if you have any queries post it below in the comment section I will try my best to resolve your queries and I will add it to my answer if required. Please give upvote if you like it.


Related Solutions

Developer User Account Create a user account using T-SQL for developers named DEVELOPER with the password...
Developer User Account Create a user account using T-SQL for developers named DEVELOPER with the password TESTACCOUNT that grants the user the ability to: Select and modify any table. Connect to and have access to all resources. In SSMS
Use the following information to create SQL commands to retrieve data from Henry Books database :...
Use the following information to create SQL commands to retrieve data from Henry Books database : For each book, list the book code, book title, publisher code, and publisher name. Order the results by publisher name. For each book published by Plume, list the book code, book title, and price. List the book title, book code, and price of each book published by Plume that has a book price of at least $14. List the book code, book title, and...
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...
Using SQL Developer ONLY! Lab 5 1. Create a lab report file (MS Word compatible) and...
Using SQL Developer ONLY! Lab 5 1. Create a lab report file (MS Word compatible) and name it as “IT4153_Lab 5_ Your D2L ID”. a. Create two tables: Employee: empID (PK), empFname, empLname, deptID(FK) and Department: deptID(PK), deptName, chairID chairID is empID from Employee table b. Insert at least 3 rows in the Department table and at least 6 rows in the Employee table. c. Create trigger on update of chairID that enforces the following business rules • One employee...
answer the following question for oracle developer: 1- ____ is the category of SQL commands to...
answer the following question for oracle developer: 1- ____ is the category of SQL commands to create, alter or drop SQL objects (create a table, drop a view) 2-____ handles access to objects. The DBA might grant select on Customers to Bob. This will allow user Bob to read the Customers table. 3- Run this query in SQL Developer: Select sysdate from dual What is sysdate? What is dual? 4-What is a surrogate key? How are surrogate keys implemented in...
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...
Using the HotelDB tables, provide the following result as a screen image. WRITE SQL to retrieve...
Using the HotelDB tables, provide the following result as a screen image. WRITE SQL to retrieve rows from any hotel with Family room types and price less than $150. use hoteldb; CREATE TABLE HOTEL ( hotelNo numeric primary key , name varchar(40) , address varchar(40) , city varchar(200) ); CREATE TABLE ROOM ( roomNo numeric Primary Key , hotelNo numeric References HOTEL , type varchar(20) , price dec(9,2) ); CREATE TABLE GUEST ( guestNo numeric primary key , name varchar(40)...
I need SQL queries for these statements 17. Display the contracts and payment methods associated with...
I need SQL queries for these statements 17. Display the contracts and payment methods associated with each referral Patient Last Name, Physician Last Name, Referral Start Date, Contract Start Date, Payment Method Sort Order: Payment Method - ascending Physician Last Name – ascending Patient Last Name – ascending Referral Start Date – ascending Contract Start Date – ascending 18. Display the number of contracts whose payment method is Insurance Number of contracts (This is a single value) 19. Display the...
Use the SQL Developer to create the four tables EMP, DEPT, PROJ, EMP_PROJ with the appropriate...
Use the SQL Developer to create the four tables EMP, DEPT, PROJ, EMP_PROJ with the appropriate constraints except FOREIGN KEY constraints. For filename, use CREATE.sql accordingly. Import data from the csv files to EMP, DEPT, and PROJ tables. Check that all data for EMP, DEPT, and PROJ tables has been imported. __________________________ employees.csv empNo,fname,lname,address,sex,salary,position,deptNo 1000,Steven,King,"731 Fondren, Houston, TX",M,30000,Programmer,60 1007,Diana,Lorentz,"638 Voss, Bellaire, TX",F,24000,Clerk,20 2002,Pat,Fay,"3321 Castle, Spring, TX",F,15000,Sales Representative,80 1760,Jonathan,Taylor,"561 Rice, Houston, TX",M,60000,Manager,20 1740,Ellen,Abel,"890 Stone, Houston, TX",F,65000,Manager,60 2060,William,Gietz,"450 Berry, Bellaire, TX",M,65000,Manager,80 2000,Jennifer,Whalen,"980...
​​​​​​ Write a SQL statement to retrieve user account information (username, account_status, default_tablespace, temporary_tablespace, and created...
​​​​​​ Write a SQL statement to retrieve user account information (username, account_status, default_tablespace, temporary_tablespace, and created date) of your account. Write a SQL statement to retrieve the “USERS” table space information (tablespace name, block_size, initial extent, max_extents). Write a SQL statement to retrieve the physical file information (file name, tablespace name, bytes, blocks, and status).  
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT