Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
34Activity
0 of .
Results for:
No results containing your search query
P. 1
Procedures

Procedures

Ratings:

5.0

(1)
|Views: 635|Likes:
Published by api-3831209

More info:

Published by: api-3831209 on Oct 18, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

03/18/2014

pdf

text

original

Procedures

-A procedure is a subprogram that performs a specific
action.
-You write procedures using the syntax :-

PROCEDURE name [(parameter[, parameter, ...])] IS
[local declarations]
BEGIN
executable statements
[EXCEPTION
exception handlers]
END [name];
where :-
1)parameter stands for the following syntax:
parameter_name [IN | OUT | IN OUT] datatype [{:= |
DEFAULT} expr]
2)You cannot impose the NOT NULL constraint on a
parameter.
3)you cannot specify a constraint on the datatype. For
example, the following declaration ofemp_id is illegal:

PROCEDURE ... (emp_id NUMBER(4)) IS -- illegal; should
be NUMBER
BEGIN ... END;

4)A procedure has two parts:
-the specification.
-the body.
5)The procedure specification :-
-begins with the keyword PROCEDURE .
-ends with the procedure name or a parameter list.
6)Parameter declarations areoptional. Procedures that
take no parameters are written without parentheses.

7)The procedure body begins with the keyword IS and ends
with the keyword END followed by an optional procedure
name.

8) The procedure body has three parts:
1) a declarative part.
2) an executable part.
3) and an optional exception-handling part.

9)The declarative part contains:
-local declarations, which are placed between the
keywords IS and BEGIN.
-The keyword DECLARE, which introduces declarations
in an anonymous PL/SQL block, is not used.
-The executable part contains statements, which are
placed between the keywords BEGIN and EXCEPTION
(or END). At least one statement must appear in
the executable part of a procedure.
-The NULL statement meets this requirement.
-The exception-handling part contains exception
handlers, which are placed between the keywords
EXCEPTION and END.
EXMAPLE:
Consider the procedureraise_salary, which increases the
salary of an employee:

PROCEDURE raise_salary (emp_id INTEGER, increase REAL) IS
current_salary REAL;
salary_missing EXCEPTION;

BEGIN
SELECT sal INTO current_salary FROM emp
WHERE empno = emp_id;
IF current_salary IS NULL THEN
RAISE salary_missing;
ELSEUPDATE emp SET sal = sal + increase
WHERE empno = emp_id;
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
INSERT INTO emp_audit VALUES (emp_id, 'No such
number');
WHEN salary_missing THEN

INSERT INTO emp_audit VALUES (emp_id, 'Salary is
null');
END raise_salary;

When called:
-this procedure accepts an employee number and
a salary increase amount.
-It uses the employee number to select the current
salary from theemp database table.
-If the employee number is not found or if the
current salary is null, an exception is raised.
Otherwise, the salary is updated.
A procedure is called as a PL/SQL statement. For example,
you might call the procedureraise_salary as follows:
CALLING: raise_salary(emp_num, amount);
Stored Procedures and Functions
A stored procedure or function is a PL/SQL program unit
that:-
\u2022
has a name.
\u2022
can take parameters, and return values.
\u2022
is stored in the data dictionary.
\u2022
can be invoked by many users.
Note: The term storedprocedure is sometimes used
generically in this Guide to cover both stored procedures
and stored functions.
Procedure Names
-Since a procedure is stored in the database, it must be
named:-
1- to distinguish it from other stored procedures.

2- to make it possible for applications to call it.
-Each publicly-visible procedure in a schema must have a
unique name.
- The name must be a legal PL/SQL identifier.

Note: If you plan to call a stored procedure using a stub

generated(what it means?) by SQL*Module, the stored
procedure name must also be a legal identifier in the
calling host 3GL language such as Ada or C.

-Procedure and function names that are part of packages
can beoverloaded. That is, you can use the same name for

different subprograms as long as their formal parameters
differ in number, order, or datatype family. See the
PL/SQL User's Guide and Reference for more information

about subprogram name overloading.

Activity (34)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
gaurav_rdso liked this
MohanReddy81 liked this
John Peter liked this
ntpcs liked this
petrus01id liked this
petrus01id liked this
mann2323 liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->