PLSQL Exercise 6
PLSQL Exercise 6
PLSQL Exercise 6
1) Write a procedure to fetch data from table SALES for a given parameter orderid and
display the data(use ROWTYPE to capture the data)
2) Modify the above procedure to return the row you have stored in the ROWTYPE
variable using an OUT parameter.
3) Write a procedure to call the above procedure and display the data.
5) Write a procedure to call the procedure you have created in #2 and update the column
TOTAL_AMOUNT to SALES_AMOUNT + TAX_AMOUNT in the SALES table.
1)
DBMS_OUTPUT.PUT_LINE (SALE_REC.SALES_DATE);
DBMS_OUTPUT.PUT_LINE (SALE_REC.ORDER_ID);
DBMS_OUTPUT.PUT_LINE (SALE_REC.PRODUCT_ID);
DBMS_OUTPUT.PUT_LINE (SALE_REC.CUSTOMER_ID);
DBMS_OUTPUT.PUT_LINE (SALE_REC.SALESPERSON_ID);
DBMS_OUTPUT.PUT_LINE (SALE_REC.QUANTITY);
DBMS_OUTPUT.PUT_LINE (SALE_REC.UNIT_PRICE);
DBMS_OUTPUT.PUT_LINE (SALE_REC.SALES_AMOUNT);
DBMS_OUTPUT.PUT_LINE (SALE_REC.TAX_AMOUNT);
DBMS_OUTPUT.PUT_LINE (SALE_REC.TOTAL_AMOUNT);
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No such Order!');
WHEN TOO_MANY_ROWS THEN
DBMS_OUTPUT.PUT_LINE('You got more than 1 row!');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Error !');
END;
2)
S_REC := SALE_REC;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No such Order!');
WHEN TOO_MANY_ROWS THEN
DBMS_OUTPUT.PUT_LINE('You got more than 1 row!');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Error !');
END;
3)
5)
COMMIT;
END;
SALE_REC SALES_INFO_REC;
BEGIN
DBMS_OUTPUT.PUT_LINE (SALE_REC.SALES_DATE);
DBMS_OUTPUT.PUT_LINE (SALE_REC.ORDER_ID);
DBMS_OUTPUT.PUT_LINE (SALE_REC.PRODUCT_ID);
DBMS_OUTPUT.PUT_LINE (SALE_REC.CUSTOMER_ID);
DBMS_OUTPUT.PUT_LINE (SALE_REC.QUANTITY);
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No such Order!');
WHEN TOO_MANY_ROWS THEN
DBMS_OUTPUT.PUT_LINE('You got more than 1 row!');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Error !');
END;
EXEC FETCH_SALES_USER(1268);