Commit 58fb1f3b authored by michael lundquist's avatar michael lundquist
Browse files

done with week 10

parent e004029e
......@@ -41,32 +41,20 @@ re-do 9, with a different cursor
*/
declare
pldege_cur SYS_REFCURSOR;
lv_id_num DD_PLEDGE.IDPLEDGE%TYPE := 0;
lv_text_str VARCHAR2(100) := '';
TYPE pledge_row IS RECORD(
ID DD_PAYMENT.ID_PLEDGE%TYPE,
AMT DD_PAYMENT.PAYAMT%TYPE,
MONTHS DD_PLEDGE.PAYMONTHS%TYPE,
PAYDATE DD_PAYMENT.PAYDATE%TYPE
);
CURSOR pledges IS
SELECT IDPLEDGE, PAYMONTHS
FROM DD_PLEDGE
order by IDPLEDGE;
i pledge_row;
CURSOR PAYMENTS(id DD_PLEDGE.IDPLEDGE%TYPE) IS
select PAYAMT, PAYDATE from DD_PAYMENT
WHERE IDPLEDGE = id order by PAYDATE;
begin
open pledge_cur for SELECT IDPLEDGE, PAYAMT, PAYMONTHS, PAYDATE
FROM DD_PAYMENT JOIN DD_PLEDGE USING (IDPLEDGE)
order by IDPLEDGE, PAYDATE;
FOR i IN pledge_cur LOOP
if i.IDPLEDGE != lv_id_num THEN
lv_text_str := 'first payment ';
lv_id_num := i.IDPLEDGE;
else
lv_text_str := '';
end if;
dbms_output.put_line( lv_text_str || 'ID: ' || i.IDPLEDGE || ' amt: ' || i.PAYAMT || ' months: ' || i.PAYMONTHS || ' paydate: ' || i.PAYDATE );
END LOOP;
FOR ple IN pledges LOOP
dbms_output.put( 'first payment: ');
for pay in payments(ple.IDPLEDGE) loop
dbms_output.put_line( 'ID: ' || ple.IDPLEDGE || ' amt: ' || pay.PAYAMT || ' months: ' || ple.PAYMONTHS || ' paydate: ' || pay.PAYDATE );
end loop;
end loop;
end;
/
\ No newline at end of file
# Ch4 hands on answers
## 4.9
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.
```plsql
declare
CURSOR pledges IS
SELECT IDPLEDGE, PAYAMT, PAYMONTHS, PAYDATE
FROM DD_PAYMENT JOIN DD_PLEDGE USING (IDPLEDGE)
order by IDPLEDGE, PAYDATE;
lv_id_num DD_PLEDGE.IDPLEDGE%TYPE := 0;
lv_text_str VARCHAR2(100) := '';
begin
FOR i IN pledges LOOP
if i.IDPLEDGE != lv_id_num THEN
lv_text_str := 'first payment ';
lv_id_num := i.IDPLEDGE;
else
lv_text_str := '';
end if;
dbms_output.put_line( lv_text_str || 'ID: ' || i.IDPLEDGE || ' amt: ' || i.PAYAMT || ' months: ' || i.PAYMONTHS || ' paydate: ' || i.PAYDATE );
END LOOP;
end;
/
```
![9 a](./pics/p9.PNG)
![9b](./pics/p9a.PNG)
## problem 10
re-do 9, with a different cursor
```plsql
declare
CURSOR pledges IS
SELECT IDPLEDGE, PAYMONTHS
FROM DD_PLEDGE
order by IDPLEDGE;
CURSOR PAYMENTS(id DD_PLEDGE.IDPLEDGE%TYPE) IS
select PAYAMT, PAYDATE from DD_PAYMENT
WHERE IDPLEDGE = id order by PAYDATE;
begin
FOR ple IN pledges LOOP
dbms_output.put( 'first payment: ');
for pay in payments(ple.IDPLEDGE) loop
dbms_output.put_line( 'ID: ' || ple.IDPLEDGE || ' amt: ' || pay.PAYAMT || ' months: ' || ple.PAYMONTHS || ' paydate: ' || pay.PAYDATE );
end loop;
end loop;
end;
/
```
![p10a](./pics/p10a.PNG)
![p10b](./pics/p10b.PNG)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment