Stored Procedures
Stored Procedures
Stored Procedures
Procedures
Objectives
Uses
of procedures
Create procedures
Features of parameter modes
Procedures with parameters
Invoke a procedure
Remove a procedure
Examples
Stored Procedures
Advantages
General Structure
CREATE [OR REPLACE] PROCEDURE procedure_name
[ (parameter [,parameter]) ]
[IS | AS]
[declaration_section]
BEGIN
executable_section
[EXCEPTION
exception_section]
END [procedure_name];
Example I
Define a variable
By default, it is IN
Developing Procedures
EXAMPLE - II
CREATE OR REPLACE PROCEDURE raise_salary
(p_id IN employees.employee_id%TYPE)
IS
BEGIN
UPDATE employees SET salary = salary * 1.10
WHERE employee_id = p_id;
END raise_salary;
/
To invoke a procedure in iSQL*Plus, use the EXECUTE command.
EXECUTE raise_salary (176)
To invoke a procedure from another procedure, use a direct call. At the location of
calling the new procedure, enter the procedure name and actual parameters.
raise_salary (176);
Example - III
CREATE OR REPLACE PROCEDURE query_emp
( p_id IN employees.employee_id%TYPE,
p_name OUT employees.last_name%TYPE,
p_salary OUT employees.salary%TYPE,
p_comm OUT employees.commission_pct%TYPE)
IS
BEGIN
SELECT last_name, salary, commission_pct
INTO p_name, p_salary, p_comm
FROM employees
WHERE employee_id = p_id;
END query_emp;
/
Procedure created
continue.
Removing Procedures
Drop a procedure stored in the database.
Syntax:
THANK YOU