











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!












Where do Stored Procedures and Functions Reside?
How the Oracle engine creates a Procedure/Function?
1. Security: Stored procedures can help enforce data security. 2. Performance: It improves database performance in the following ways:
3. Memory Allocation: The amount of memory used reduces as stored procedures have shared memory capabilities. Only one copy of procedure needs to be loaded for execution by multiple users. Once a copy of the procedure is opened in the Oracle engineās memory, other users who have permissions may access them when required. 4. Productivity: By writing procedures redundant coding can be avoided, increasing productivity. 5. Integrity: A procedure needs to be tested only once to guarantee that it returns an accurate result. Since procedures are stored in the Oracle engineās they become a part of the engineās resource. Hence the responsibility of maintaining their integrity rests with the Oracle Engine.
How To DELETE A Stored Procedure?
Example
Table: Challan_Details Column Name Data Type Size Attributes Challan_no Varchar2 6 PK/FK references Challan_no of Challan_header Table Product_no Varchar2 20 PK/FK references product_no of product_master Table Qty_disp Number 10,2 Not Null Table: Challan_Header Column Name Data Type Size Attributes Challan_no Varchar2 6 PK / First two letters must start with āCHā. Order_no Varchar2 20 FK references s_order_no of sales_order Table. Challan_Date Date Not Null. Billed_yn Char 1 Values (āYā,āNā). Default āNā
Table: Sales_Order Column Name Data Type Size Attributes Order_no Varchar2 6 PK / First two letters must start with āO. Order_date date Client_no Number 10,2 FK references client_no of client_master table. Dely_Addr Varchar2 25 Salesman_No Varchar2 6 FK references salesman_no of salesman_master table Dely_Type Char 1 Billed_yn Char 1 Dely_date Date canāt be less than order date Order_Status Varchar2 10 Values (In Process, Fulfilled, BackOrder or Cancelled)
CREATE OR REPLACE PROCEDURE proc_update (vproductno IN char, vsorderno IN char, quantity IN number) IS Total_qty_ordered number (8); Total_qty_disp number (8); BEGIN UPDATE product_master SET qty_in_hand = qty_in_hand-quantity (/Updating the qty_in_hand in product_master table/) WHERE product_no = vproductno; SELECT sum(qty_ordered), sum (qty_disp) (/Checking in the sales_order_details table the total INTO total_qty_ordered, total_qty_disp quantity ordered and the total quantity dispatched FROM sales_order_details for a certain sales_order and stuffing the values WHERE delorder_no=vsorderno; into memory variables /) IF total_qty_ordered = total_qty_disp THEN UPDATE sales_order SET order_status = āFulfilledā(/ Comparing the total_quantity ordered with WHERE order_no = vsorderno; the total quantity dispatched and updating the ELSIF total_qty_disp = 0 THEN order_status in sales_order table/) UPDATE sales_order SET order_status = āBackorderā WHERE order_no = vsorderno; Else UPDATE sales_order SET order_status = āIn Processā WHERE order_no = vsorderno; END IF; END;
The functionality of the PL/SQL block of code will be as follows: