Sunday, 14 February 2016

Write a cursor that will take input as a month. Display the inputted month wise report in the following format.

Write a cursor that will take input as a month. Display the inputted month wise report in the  following format.


DECLARE
MONTH VARCHAR2(3);
CONS NUMBER;
TOT NUMBER;
CURSOR C1 IS SELECT A.CUST_NO, A.CUST_NAME, B.PREV_READ, B.CURR_READ, B.UNIT_PRICE FROM CUSTOMER_MST A,
 CUSTOMER_DTL B WHERE A.CUST_NO=B.CUST_NO AND B.BILL_MON='DEC';


CUST_N CUSTOMER_MST.CUST_NAME%TYPE;
CURR_R CUSTOMER_DTL.CURR_READ%TYPE;
PREV_R CUSTOMER_DTL.PREV_READ%TYPE;
U_PRICE CUSTOMER_DTL.UNIT_PRICE%TYPE;
C_NO CUSTOMER_DTL.CUST_NO%TYPE;
BEGIN
OPEN C1;
MONTH:='&MONTH';
LOOP
FETCH C1 INTO C_NO, CUST_N, PREV_R, CURR_R, U_PRICE;
CONS:=CURR_R-PREV_R;
TOT:=CONS*U_PRICE;
EXIT WHEN C1%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(C_NO||' '||CUST_N||' '||CONS||' '||TOT);
END LOOP;
CLOSE C1;
END;
/

No comments:

Post a Comment