Stored Procedures and stored functions refer to the stored procedures and stored functions that are stored in the database and called by all user programs. The stored procedure does not return values. Stored functions return values
Stored Procedures and stored functions refer to the stored procedures and stored functions that are stored in the database and called by all user programs. The stored procedure does not return values. Stored functions return values
Stored Procedures and functions
A subroutine stored in a database for calls by all user programs is called a stored procedure and a stored function.
The stored procedure does not return values. Stored functions return values
Create a stored procedure
Use the create procedure command to CREATE a stored PROCEDURE and function.
Syntax:
Create [or replace] PROCEDURE process name (parameter list)
AS
PLSQL subprogram body;
Example of Stored Procedure: 10% of the original salary of the specified employee
/*
Pay 10% of the original salary for the specified employee, and print the salary before and after the salary
*/
SQL> create or replace procedure raiseSalary (empid in number)
As
PSal emp. sal % type; -- save the current employee salary
Begin
-- Query the employee's salary
Select sal into pSal from emp where empno = empid;
-- Raise the employee's salary
Update emp set sal = sal * 1.1 where empno = empid;
-- Print the salary before and after the increase
Dbms_output.put_line ('employee ID: '| empid |' before salary increase
'| Psal | 'salary increase' | psal * 1.1 );
End;
1/
Procedure created
-- Stored procedure call
-- Method 1
SQL> set serveroutput on
SQL> exec raisesalary (7369 );
Employee No.: 7369 before salary increase
800 880 after salary increase
Method 2
Set serveroutput on
Begin
Raisesalary (7369 );
End;
/
PL/SQL procedure successfully completed
Storage Functions
A Function is a named storage program that can contain parameters and return a calculated value. The structure of a function is similar to that of a process, but a RETURN clause must be provided to RETURN the function value. Function Description specifies the function name, result value type, and parameter type.