0% found this document useful (0 votes)
30 views

What Is A Stored Procedure

A stored procedure is a named PL/SQL block that performs a specific task and can be repeatedly executed. It has a header with a name and parameters and a body with declaration, execution, and exception sections similar to a PL/SQL block. Procedures allow passing parameters in three ways - IN, OUT, and IN OUT. The general syntax to create a procedure uses the CREATE OR REPLACE statement and identifies the procedure name, parameters, and sections. Procedures are executed using the EXECUTE statement at the SQL prompt or by calling the procedure within another procedure.

Uploaded by

avinash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

What Is A Stored Procedure

A stored procedure is a named PL/SQL block that performs a specific task and can be repeatedly executed. It has a header with a name and parameters and a body with declaration, execution, and exception sections similar to a PL/SQL block. Procedures allow passing parameters in three ways - IN, OUT, and IN OUT. The general syntax to create a procedure uses the CREATE OR REPLACE statement and identifies the procedure name, parameters, and sections. Procedures are executed using the EXECUTE statement at the SQL prompt or by calling the procedure within another procedure.

Uploaded by

avinash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

What is a Stored Procedure?

A stored procedure or in simple a proc is a named PL/SQL block which performs one or more specific
task. This is similar to a procedure in other programming languages.
A procedure has a header and a body. The header consists of the name of the procedure and the
parameters or variables passed to the procedure. The body consists or declaration section, execution
section and exception section similar to a general PL/SQL Block.
A procedure is similar to an anonymous PL/SQL Block but it is named for repeated usage.

Procedures: Passing Parameters


We can pass parameters to procedures in three ways.
1) IN-parameters
2) OUT-parameters
3) IN OUT-parameters
A procedure may or may not return any value.

General Syntax to create a procedure is:


CREATE [OR REPLACE] PROCEDURE proc_name [list of parameters]
IS
Declaration section
BEGIN
Execution section
EXCEPTION
Exception section
END;
IS - marks the beginning of the body of the procedure and is similar to DECLARE in anonymous PL/SQL
Blocks. The code between IS and BEGIN forms the Declaration section.
The syntax within the brackets [ ] indicate they are optional. By using CREATE OR REPLACE together
the procedure is created if no other procedure with the same name exists or the existing procedure is
replaced with the current code.

Procedures: Example
The below example creates a procedure employer_details which gives the details of the employee.
1> CREATE OR REPLACE PROCEDURE employer_details
2> IS

3> CURSOR emp_cur IS


4> SELECT first_name, last_name, salary FROM emp_tbl;
5> emp_rec emp_cur%rowtype;
6> BEGIN
7> FOR emp_rec in sales_cur
8> LOOP
9> dbms_output.put_line(emp_cur.first_name || ' ' ||emp_cur.last_name
10>
|| ' ' ||emp_cur.salary);
11> END LOOP;
12>END;
13> /

How to execute a Stored Procedure?


There are two ways to execute a procedure.
1) From the SQL prompt.
EXECUTE [or EXEC] procedure_name;
2) Within another procedure simply use the procedure name.
procedure_name;

You might also like