A stored procedure is a set of functions in order to complete a specific set of sql statement, is a piece of code fragments sql, after compiled stored in the database, the user and the parameters are given (if the stored procedure on reference given by the presence of the specified name of the stored procedure, not presence would not have given parameter) to execute it. Because it is a piece of code sql statement and have compiled stored in the database, so its efficiency is very high.
Create a stored procedure is as follows:
create [or replace] procedure procedure name [(parameter name in | out data types)]
AS | IS
declare variables of
the begin
PLSQL subroutine body;
end; // If it is, the back end to add the name of course.
Call a stored procedure
First: call the stored procedure name (parameter);
The second: begin
Stored procedure name (parameters);
end;
For example 1: give employees a raise designated 100, and print out the wage front and back of rising up
Create a stored procedure:
create or replace procedure addsal(eno in number) is
pemp emp%rowtype;
begin
select * into pemp from emp where empno = eno;
update emp set sal = sal + 100 where empno = eno;
dbms_output.put_line('ename:' || pemp.ename || 'after' || (pemp.sal+100));
end addsal;
Call a stored procedure:
The first call: call addsal (7369);
The second call:
the begin
addsal (ENO => 7369);
the commit; // because oracle database manually submitted, all deletions involved must change the commit;
End;
Example 2: Output names and salaries of all employees
Create a stored procedure:
Procedure AS infoemp Replace or Create
Cursor allemp IS
SELECT * from EMP; // Create a cursor
enemp EMP% ROWTYPE;
the begin
Open allemp;
Loop
FETCH allemp
INTO enemp; // fetch cycle using data from the cursor
dbms_output.put_line (enemp.ename || '' || enemp.sal);
exit When allemp% NOTFOUND; // exit the loop condition
End loop;
Close allemp;
End;
Call a stored procedure:
First: call infoemp ();
The second: the begin
infoemp ();
End;
These are the basic knowledge and usage of the stored procedure oracle database.