Week5_Solutions - Hands-On Assignments Part I Assignment 5-1 DECLARE lv_test_date DATE:='10-DEC-2012 lv_test_num NUMBER(3:= 10 lv_test_txt

Week5_Solutions - Hands-On Assignments Part I...

This preview shows page 1 - 3 out of 3 pages.

Hands-On Assignments Part I Assignment 5-1 DECLARE lv_test_date DATE := '10-DEC-2012'; lv_test_num NUMBER(3) := 10; lv_test_txt VARCHAR2(10); BEGIN lv_test_txt := '???????'; DBMS_OUTPUT.PUT_LINE(lv_test_date); DBMS_OUTPUT.PUT_LINE(lv_test_num); DBMS_OUTPUT.PUT_LINE(lv_test_txt); END; Assignment 5-2 Assignment 5-3 DECLARE lv_total_num NUMBER(6,2) := 150; BEGIN IF lv_total_num > 200 THEN Retrieve purchase total value Yes Is total > $200? Display rating = HIGH No Yes Is total > $100? Display rating = MID No Display rating = LOW
DBMS_OUTPUT.PUT_LINE('HIGH'); ELSIF lv_total_num > 100 THEN DBMS_OUTPUT.PUT_LINE('MID'); ELSE DBMS_OUTPUT.PUT_LINE('LOW'); END IF; END; Assignment 5-4 DECLARE lv_total_num NUMBER(6,2) := 150; BEGIN CASE WHEN lv_total_num > 200 THEN DBMS_OUTPUT.PUT_LINE('HIGH'); WHEN lv_total_num > 100 THEN DBMS_OUTPUT.PUT_LINE('MID'); ELSE DBMS_OUTPUT.PUT_LINE('LOW'); END CASE; END; Assignment 5-5 DECLARE lv_start_date DATE := '01-OCT-2012'; lv_payamt_num NUMBER(8,2) := 20; lv_paymths_num NUMBER(8,2) := 24; lv_bal_num NUMBER(8,2) := 0; lv_duedate_date DATE; lv_duedate_txt VARCHAR2(25); BEGIN lv_bal_num := lv_payamt_num * lv_paymths_num; lv_duedate_date := lv_start_date; FOR i IN 1..lv_paymths_num LOOP lv_bal_num := lv_bal_num - lv_payamt_num; lv_duedate_txt := TO_CHAR(lv_duedate_date,'mm/dd/yyyy'); DBMS_OUTPUT.PUT_LINE('Pay #: ' || i || ' Due: ' || lv_duedate_txt || ' Amt: ' || TO_CHAR(lv_payamt_num,'$999.99') || ' Bal: ' || TO_CHAR(lv_bal_num,'$9,999.99')); lv_duedate_date := ADD_MONTHS(lv_duedate_date,1); END LOOP; END; 6) DECLARE lv_start_date DATE := '01-OCT-2012'; lv_payamt_num NUMBER(8,2) := 20; lv_paymths_num NUMBER(8,2) := 24; lv_paid_num NUMBER(8,2) := 0; lv_duedate_date DATE; lv_duedate_txt VARCHAR2(25); lv_cnt_num NUMBER(2) := 1; BEGIN lv_duedate_date := lv_start_date; WHILE lv_cnt_num <= lv_paymths_num LOOP lv_paid_num := lv_paid_num + lv_payamt_num;
lv_duedate_txt := TO_CHAR(lv_duedate_date,'mm/dd/yyyy'); DBMS_OUTPUT.PUT_LINE('Pay #: ' || lv_cnt_num || ' Due: ' || lv_duedate_txt || ' Amt: ' || TO_CHAR(lv_payamt_num,'$999.99') || ' Total Paid: ' || TO_CHAR(lv_paid_num,'$9,999.99')); lv_duedate_date := ADD_MONTHS(lv_duedate_date,1); lv_cnt_num := lv_cnt_num + 1; END LOOP; END;

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture