To know more about Procedures in pl/sql ,let us first start with the basic requirement of procedures in pl/sql.
Procedures are a type of schema object which can be stored in a database.
Procedures are a type of subprogram that perform a particular action.
Promotes maintanability and reusability.
syntax to create procedure:-
create[OR Replace] Procedure Procedure_name
[parameter1] datatype1
[parameter2]datattype2
Is/As
[local variable declaration;...]
begin
action
end [Procedure_name];
use the Create clause to create the Standalone Procedure that is stored in the Oracle Database
Use the Replace clause to replace the already existing Procedure name with the name you want to display the procedure with.
let us take the example for increase salary
Code Listing 1: increase_salary procedure with FOR loop
BEGIN increase_salary (15, .10);
END;
the PL/SQL engine will “switch” over to the SQL engine 100 times, once for each row being updated. Tom Kyte, of AskTom (asktom.oracle.com), refers to row-by-row switching like this as “slow-by-slow processing,” and it is definitely something to be avoided.
Procedures are a type of schema object which can be stored in a database.
Procedures are a type of subprogram that perform a particular action.
Promotes maintanability and reusability.
syntax to create procedure:-
create[OR Replace] Procedure Procedure_name
[parameter1] datatype1
[parameter2]datattype2
Is/As
[local variable declaration;...]
begin
action
end [Procedure_name];
use the Create clause to create the Standalone Procedure that is stored in the Oracle Database
Use the Replace clause to replace the already existing Procedure name with the name you want to display the procedure with.
let us take the example for increase salary
Code Listing 1: increase_salary procedure with FOR loop
PROCEDURE increase_salary (
department_id_in IN employees.department_id%TYPE,
increase_pct_in IN NUMBER)
IS
BEGIN
FOR employee_rec
IN (SELECT employee_id
FROM employees
WHERE department_id =
increase_salary.department_id_in)
LOOP
UPDATE employees emp
SET emp.salary = emp.salary +
emp.salary * increase_salary.increase_pct_in
WHERE emp.employee_id = employee_rec.employee_id;
END LOOP;
END increase_salary;
Suppose there are 100 employees in department 15. When I execute this block,
BEGIN increase_salary (15, .10);
END;
the PL/SQL engine will “switch” over to the SQL engine 100 times, once for each row being updated. Tom Kyte, of AskTom (asktom.oracle.com), refers to row-by-row switching like this as “slow-by-slow processing,” and it is definitely something to be avoided.