Creating stored subprograms
You create a stored subprogram using the CREATE PROCEDURE
command. In this section, let us create a sample stored procedure in the HR schema and name it salary_increment
. The stored procedure does the following:
1. Accepts
EMP_NO
as input.2. Fetches the current salary of the employee.
3. Calculates the increment on the salary.
4. If the salary is greater than 1000 then raise it by 2 percent. If the salary is between 501 and 999, increment it by 5 percent, and if the salary is less than or equal to 500, increment it by 10 percent.
5. Increment the salary of the given employee in the
EMP
table.6. Commits the changes.
The following is a screenshot of a PL/SQL stored procedure:
At this point you should be able to successfully create the salary_increment
procedure. Before we execute this procedure, let us make a note of the salary of "Tom Green" by querying the EMP
table. The following screenshot shows the query:
From the query shown in the preceding screenshot, we know...