Create replace Procedure [Course project]
Your solution should follow these steps:
- You began your procedure by typing
CREATE OR REPLACE PROCEDURE SHIPPING_FEE
and pressing Enter.
- To define the incoming parameter, you typed
(I_SALES_ID IN NUMBER) AS
and approved the entry by pressing Enter.
- You began typing in the declaration section to define the first variable. You typed
V_SHIPPING_FEE NUMBER;
and approved the entry by pressing Enter.
- Then you typed
BEGIN
and pressed Enter to start the main block of the procedure.
- Next, you typed
SELECT TOTAL_SALE_AMOUNT,
and pressed Enter. This was the first line of a query.
- You continued to define another part of the query by typing
V_TOTAL_SALE, V_TOTAL_ITEM, V_TAX
and pressing Enter.
- You finished the query by typing
SALES_ID = I_SALES_ID;
and pressing Enter.
- Next, you created a calculation for the shipping fee by typing
V_SHIPPING_FEE := V_TOTAL_ITEM * .10;
and pressing Enter.
- You finished the second calculation for the total sales by typing
V_TOTAL_ITEM + V_SHIPPING_FEE + V_TAX;
and pressing Enter.
- You create the beginning of an update command by typing
UPDATE CUSTOMER_SALE
and pressing Enter.
- Then you continue by defining the first column to be updated by typing
SET TOTAL_SALE_AMOUNT = V_TOTAL_SALE,
and pressing Enter.
- The rest of the UPDATE command was added for you. Now, you type
END;
and press Enter to complete the body of the procedure.
- To execute your block, you typed
/
at the SQL4 prompt and pressed Enter.
- SQL*Plus then displayed the result of the compilation of your block.
- Next, you executed the procedure by typing EXECUTE SHIPPING_FEE(107); and pressing Enter. You see the results of the command in the final screen.
The complete text of the procedure is:
CREATE OR REPLACE PROCEDURE SHIPPING_FEE
(I_SALES_ID IN NUMBER) AS
BEGIN
DECLARE
V_SHIPPING_FEE NUMBER;
V_TOTAL_ITEM NUMBER;
V_TOTAL_SALE NUMBER;
V_TAX NUMBER;
BEGIN
-- query the table now.
SELECT TOTAL_SALE_AMOUNT,
TOTAL_ITEM_AMOUNT, TAX_AMOUNT
INTO
V_TOTAL_SALE,V_TOTAL_ITEM, V_TAX
FROM CUSTOMER_SALE
WHERE SALES_ID = I_SALES_ID;
V_SHIPPING_FEE := V_TOTAL_ITEM * .10;
V_TOTAL_SALE :=
V_TOTAL_ITEM + V_SHIPPING_FEE + V_TAX;
-- update the table now.
UPDATE CUSTOMER_SALE
SET TOTAL_SALE_AMOUNT = V_TOTAL_SALE,
SHIPPING_HANDLING_FEE = V_SHIPPING_FEE
WHERE SALES_ID = I_SALES_ID;
END;
END;