PLSQL Exercise 5
PLSQL Exercise 5
Move all the below procedures/functions which you have written in the Exercise #4 to a
package (create package specification and then create package body).
1) Write a procedure to fetch data from table SALES for a given parameter orderid and
display the data.
Fetch data from table SALES for a given parameter orderid and display the data.
Return the number of rows(using OUT parameter) in the SALES table for that
sales date (get sales date from the about operation)
3) Write a function which accepts 2 numbers n1 and n2 and returns the power of n1 to n2.
(Example: If I pass values 10 and 3, the output should be 1000)
4) Write a function to display the number of rows in the SALES table for a given sales date.
Answers
END;
DBMS_OUTPUT.PUT_LINE (L_DATE);
DBMS_OUTPUT.PUT_LINE (L_ORDERID);
DBMS_OUTPUT.PUT_LINE (L_PRODUCTID);
DBMS_OUTPUT.PUT_LINE (L_CUSTOMERID);
DBMS_OUTPUT.PUT_LINE (L_SALESPERSONID);
DBMS_OUTPUT.PUT_LINE (L_QUANTITY);
DBMS_OUTPUT.PUT_LINE (L_UNITPRICE);
DBMS_OUTPUT.PUT_LINE (L_SALESAMOUNT);
DBMS_OUTPUT.PUT_LINE (L_TAXAMOUNT);
DBMS_OUTPUT.PUT_LINE (L_TOTALAMOUNT);
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;
DBMS_OUTPUT.PUT_LINE (L_DATE);
DBMS_OUTPUT.PUT_LINE (L_ORDERID);
DBMS_OUTPUT.PUT_LINE (L_PRODUCTID);
DBMS_OUTPUT.PUT_LINE (L_CUSTOMERID);
DBMS_OUTPUT.PUT_LINE (L_SALESPERSONID);
DBMS_OUTPUT.PUT_LINE (L_QUANTITY);
DBMS_OUTPUT.PUT_LINE (L_UNITPRICE);
DBMS_OUTPUT.PUT_LINE (L_SALESAMOUNT);
DBMS_OUTPUT.PUT_LINE (L_TAXAMOUNT);
DBMS_OUTPUT.PUT_LINE (L_TOTALAMOUNT);
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;
RETURN POWER_VALUE;
EXCEPTION
WHEN others THEN
dbms_output.put_line ('Error!');
END;
RETURN T_ROWS;
EXCEPTION
WHEN no_data_found THEN
dbms_output.put_line ('No orders for the given date!');
WHEN others THEN
dbms_output.put_line ('Error!');
END;
END;