PL/SQL What is the difference between procedure and function
What is the difference between procedure and function
A procedure is a collection of PL/SQL code named, defined by user and usually stored in the database.
A function is the same like procedure except that it must return a value, using the keyword RETURN.
Procedure Example
CREATE OR REPLACE PROCEDURE raise_price ( p_id IN products.product_id%Type, p_percent IN NUMBER ) IS BEGIN UPDATE products SET price= price*(1+p_percent/100) WHERE product_id = p_id; END raise_price; Begin raise_price(300,10); End;
Function Example
CREATE OR REPLACE FUNCTION Get_Price (p_id products.product_id%Type) RETURN NUMBER IS v_price products.price%TYPE :=0; BEGIN SELECT price INTO v_price FROM products WHERE product_id = p_id; RETURN v_price; END Get_Price; Begin dbms_output.put_line(Get_Price(300)); End;