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

Stored Procedures: Implementation of Business Rules Within Database Why? Improves Security, Efficiency, Integrity

Stored procedures allow implementation of business rules within a database using PL/SQL. They improve security, efficiency and integrity. Oracle stored procedures are PL/SQL blocks stored in the database that can be accessed by applications and users. They provide benefits like improved performance since code remains in the database, and security since appropriate data access is ensured. Stored procedures come in different types like triggers, functions, and procedures that can send or return values.

Uploaded by

glouvel
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views

Stored Procedures: Implementation of Business Rules Within Database Why? Improves Security, Efficiency, Integrity

Stored procedures allow implementation of business rules within a database using PL/SQL. They improve security, efficiency and integrity. Oracle stored procedures are PL/SQL blocks stored in the database that can be accessed by applications and users. They provide benefits like improved performance since code remains in the database, and security since appropriate data access is ensured. Stored procedures come in different types like triggers, functions, and procedures that can send or return values.

Uploaded by

glouvel
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 10

Stored procedures

 Implementation of business rules within


database

 Why?
 Improves security, efficiency, integrity
PL/SQL
 Oracle programming language that allows
SQL statements.
 [non –standard language]
 Can combine data manipulation and query
processing within a block of procedural
code.
Oracle Stored procedures
 These are PL/SQL blocks stored in the
database
 they are database objects, similar to tables
 can be accessed by client applications and
session users.
[Microsoft SQL server has its own language
as do other DB vendors]
Benefits of stored procedures
 Performance
All code remains in the database
only parameters are passed in calls
 Security
– stored procedures are written for all update
methods to tables ensuring appropriate access
to and management of data changes.
– Allows users with low access permissions to
use stored procedures from library
Types of stored procedures
 Triggers
linked to specific changes occurring in database
they will be executed as a result of database values
 functions [as in other languages allow a value
to be obtained and returned]
** must return a value when called
 procedures can send or return values
– can execute a variety of statements
PL/SQL Block Structure
Create or replace procedure procedure_name
or procedure_name(parameter list)
IS
DECLARE [only required in a nested block]
declarations: variables, cursors, user-defined
exceptions
BEGIN mandatory
executable SQL & PL/SQL statements
EXCEPTION optional
exception handling

END [procedure_name optional] ; mandatory


/
Syntax of PL/SQL
• DECLARE, BEGIN , EXCEPTION do not have ;
after them
• Put ; at end of every other PL or SQL statement
including END;
• / at end of script
• assignment operator :=
• Comments single line comments start with --

multi line comments as Java /*mnb


bfhfhfdhmm*/
Example of a stored procedure

Create or replace procedure first

Is
v_dummytext varchar2(25) ;

Begin

v_dummytext := ‘Hello World’;

DBMS_OUTPUT.PUT_LINE( ‘this procedure outputs’


||v_dummytext);

End:
/
Format of a trigger
create or replace trigger BTrigCapEmp
before insert or update of JOB,ENAME
on EMP
for each row
Declare
begin
:new.JOB := upper(:new.JOB);
:new.ENAME := upper(:new.ENAME);
-- changes values to upppercase
end;

Format of function
Create or replace function fname[(parameters)]
Return datatype
Is
Declare variables / datatypes
Begin
….executable statements
Return returnValue;
Exception
End;
/

You might also like