Sie sind auf Seite 1von 35

A Major Traing Report

On
PL/SQL
Submitted in Partial fulfillment for the award of
Bachelor of Engineering
Submitted to
RAJIV GANDHI PROUDYOGIKI VISHWAVIDYALAYA
BHOPAL (M.P)

Submitted by
Ashish raghuwanshi(0133cs071013)

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 
SAGAR INSTITUTE OF RESEARCH & TECHNOLOGY, BHOPAL
SESSION-2010

SAGAR INSTITUTE OF RESEARCH & TECHNOLOGY, BHOPAL
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 
             This is to certify that the training report titled 
“PL/SQL” submitted by “Ajeet shrivastv ” student of B.E. 
“VII SEM” to the department of “ Computer science 
&engineering” , SIRT during the period “1/7/2010” to 
“2/8/2010” under the guidance  of Sourabh Umalkar, He has 
submitted this training report toward  partial fulfillment  of 
the award  to the degree of Bachelor of Engineering in “BE 
IT” of Rajiv Gandhi Proudyogiki Vishwavidyalaya during 
the academic year 2010­2011 
Chapter 1

Introduction

1: PL/SQL stands for Procedural Language extension of SQL.

2: It is a combination of SQL along with procedural features


programming languages.

3: It was developed by Oracle Corporation in the early 90’s to


enhance the capabilities of SQL.

4: Data manipulation and query statements of SQL are included


within procedural units of code.

Chapter 2
Technical details

About PL/SQL

PL/SQL the procedural extension to SQL with design features of


programming languages.

Data manipulation and query statements of SQL are include


within procedural units of code.

PL/SQL ENVIRONMENT

• It is a technology used by the Oracle server and by Oracle


Tools.

• Blocks of PL/SQL are passed and processed


By a PL/SQL Engine, which may reside within
The tool or within Oracle Server.

• PL/SQL engine separates the PL/SQL block and


SQL statements and send them individually.

• SQL statements are executed by Procedural

• Statement Executor and PL/SQL block is


Executed by SQL Statement Executor, thus
Improving performance in client-server network.

• since a single transfer is required to transmit a


Block from the application to the Oracle Server.

BENEFIT OF PL/SQL

Without PL/SQL, Oracle must process SQL statements one at a time.


Programs that issue many SQL statements require multiple calls to
the database, resulting in significant network and performance
overhead.
With PL/SQL, an entire block of statements can be sent to Oracle at
one time. This can drastically reduce network traffic between the
database and an application. you can use PL/SQL blocks and
subprograms to group SQL statements before sending them to the
database for execution. PL/SQL also has language features to
further speed up SQL statements that are issued inside a loop.
PL/SQL stored procedures are compiled once and stored in
executable form, so procedure calls are efficient. Because stored
procedures execute in the database server, a single call over the
network can start a large job. This division of work reduces network
traffic and improves response times. Stored procedures are cached
and shared among users, which lowers memory requirements and
invocation overhead.

Higher Productivity

PL/SQL lets you write very compact code for manipulating data. In
the same way that scripting languages such as Perl can read,
transform, and write data from files, PL/SQL can query, transform,
and update data in a database. PL/SQL saves time on design and
debugging by offering a full range of software-engineering features,
such as exception handling, encapsulation, data hiding, and object-
oriented data types.
PL/SQL extends tools such as Oracle Forms. With PL/SQL in these
tools, you can use familiar language constructs to build
applications. For example, you can use an entire PL/SQL block in an
Oracle Forms trigger, instead of multiple trigger steps, macros, or
user exits. PL/SQL is the same in all environments. After you learn
PL/SQL with one Oracle tool, you can transfer your knowledge to
other tools.

Support for Object-Oriented Programming


• Object types are an ideal object-oriented modeling tool, which you
can use to reduce the cost and time required to build complex
applications. Besides allowing you to create software components
that are modular, maintainable, and reusable, object types allow
different teams of programmers to develop software components
concurrently.
• By encapsulating operations with data, object types let you move
data-maintenance code out of SQL scripts and PL/SQL blocks into
methods. Also, object types hide implementation details, so that
you can change the details without affecting client programs.
• In addition, object types allow for realistic data modeling. Complex
real-world entities and relationships map directly into object types.
This direct mapping helps your programs better reflect the world
they are trying to simulate. For information on object types,

Access to Pre-defined Packages

•Oracle provides product-specific packages that define APIs you can


call from PL/SQL to perform many useful tasks. These packages
include DBMS_ALERT for using database triggers, DBMS_FILE for
reading and writing operating system (OS) text files, DBMS_HTTP for
making hypertext transfer protocol (HTTP)
callouts, DBMS_OUTPUT for display output from PL/SQL blocks and
subprograms, and DBMS_PIPE for communicating over named
pipes. For additional information on these packages, see

PROCEDURAL LANGUAGE CONTROL STRUCTURES


Procedural language control structures allow you to
do the following:
• Execute a sequence of statements conditionally
• Execute a sequence of statements iteratively in a loop
• process individually the rows return by a multiple- row query with
an explicit cursor

ERROR

1: process oracle server error with exception handling routing.

2: declare user defined error condition and process them with


exception handling rioting.

PL/SQL BLOCK STRUCTUR


Provided
a brief

introduction to the PL/SQL block and its structure. Before we explore


the construction of modules in PL/SQL, let's take a more detailed
look at the PL/SQL block.
• PL/SQL is a block-structured language. Each of the basic
programming units you write to build your application is (or should
be) a logical unit of work. The PL/SQL block allows you to reflect
that logical structure in the physical design of your programs.
• The block determines both the scope of identifiers (the area of
code in which a reference to the identifier can be resolved) and the
way in which exceptions are handled and propagated. A block may
also contain nested sub-blocks of code, each with its own scope.
• There is a common block structure to all the different types of
modules. The block is broken up into four different sections, as
follows:
Header section
• Relevant for named blocks only, the header determines the
way that the named block or program must be called. The
header includes the name, parameter list, and RETURN clause
(for a function only).
Declaration section

• The part of the block that declares variables, cursors, and sub-
blocks that are referenced in the execution and exception
sections. The declaration section is optional, but if you have
one, it must come before the execution and exception sections.
Execution section

• The part of the PL/SQL blocks containing the executable


statements, the code that is executed by the PL/SQL run-time
engine. The execution section contains the IF-THEN-ELSE,
LOOPS, assignments, and calls to other PL/SQL blocks. Every
block must have at least one executable statement in the
execution section.
Exception section

• The section that handles exceptions to normal processing


(warnings and error conditions). This final section is optional. If
it is included, control is transferred to this section when an error
is encountered. This section then either handles the error or
passes control to the block that called the current block.

PL/SQL Block Structure Examples

Types of variable

PL/SQL variable:
- Scalar
- Composite
- Reference
- Lob (large object)

Scalar = scalar data types hold a single value. The main data types
are those are those that correspond to column types in oracle
server table; PL/SQL also supports Boolean variables.

Composite = such as record, allow group of field to be defined and


manipulation in PL/SQL block.

Reference = reference data type hold value , called pointers , that


designed other program item , reference data type are not covered
in the course.

Lob(large object) = lob data type hold value, called locator, that the
location of large object (such as graphic image ) that are stored
out of line . LOB data types are discussed in details later in this
course.

Declaring Data Variables in Oracle PL/SQL Blocks

In a PL/SQL block, if you are querying a database table, you need to declare data
variables to hold column values returned from the query. The variables can be
declared of the same explicit data type as the column in the table.

Let's say we create a table:


create table dept ( deptno number(2), deptname varchar2(20));

Now we have a procedure Proc1, which queries the "dept" table to get the
department name for a given deptno. The code is as follows:
create or replace procedure proc1
as
v_deptname varchar2(20);
begin
select deptname into v_deptname
from dept
where deptno = 10;
exception
when no_data_found then
raise_application_error(-20001,'Dept 10 does not exist');
end;
This procedure will work fine until the table definition gets
altered, such that the column "deptname" reaches varchar2(30) . If the department
name for deptno =10 is longer than 20 characters in the table, then the procedure will
raise an unhandled exception of 'Value Error' because the variable v_deptname cannot
hold more than 20 characters. If you have lots of procedures
with v_deptnamedeclared as varchar2(20), you will need to modify all the
procedures.
To get around this painful process, you should
declare the variables as the column type rather than the explicit datatype of the
column. See the declaration below:
v_deptname dept.deptname%TYPE;

Now if the column size is altered, you are not required to


change any of the procedures—only recompile them. The %TYPE will automatically
assign the datatype of the column to v_deptname.

IDENTIFIER

Identifiers are used to name PL/SQL program item and


unit, which include constant, variable, exceptions. Cursors variable,
subprograms and package.

• Identifier can contain up to 30 characters, but they must start with


an alphabet characters.
• Do not choose the same for the identifier as the name of column
in a table used in the block, if PL/SQL , identifier are in the same
SQL statement and have the same name as a column, then
oracle assume that it is the column that is being referenced.
• Reserved word should be written in uppercase readability.
• An identifier consist of a later, optically followed by more letter,
number, dollars sign, underscore, and number sign other
characters such hyphens, slashes ,and spaces are illegal, as the
following example show:

Dots dashes – illegal ampersands


Debit- amount – illegal hyphen
On/off – illegal slash
User id – illegal space

OPERATORES in PL/SQL
EXAMPLE:
• Increment the counter for a loop.

v_count := v_count + 1;
• Set the value of a Boolean flag.
v_count := ( v_n1 = v_n2);

• validate whether an employee number contains a value


v_count := (v_empo is not null);

Operations in PL/SQL = When working with null, you can avoid


some common mistake by keeping in mind the following:

• Comparisons involving nulls always yield NULL.


• Applying the logical operator NOT to a null yield NULL
• In condition control statements if the condition NULL, its associate
sequence of statements is not execute.

SQL STATEMENTS IN PL/SQL

 Extract q row of data from the database by using the SELECT


command.
 Make change to rows in the database by using DML command.
 Control a transaction with the COMMIT. ROLLBACK, or SAVEPOINT,
command.
 Determine DML outcome with implicate cursor attribute.

    DECLARE
v_sal employee.sal%TYPE;
BEGIN

INSERT INTO employee VALUES (6, 'TOM LEE', 10000);

UPDATE employee SET sal = sal + 5000 WHERE empno = 6;


     SELECT sal INTO v_sal FROM employee WHERE empno = 6;
DBMS_OUTPUT.PUT_LINE('Salary increased to ' || v_sal);
DELETE FROM employee WHERE empno = 6;
    COMMIT;

END;
Chapter 3

Manipulating Data using PL/SQL

Make changes to database tables by using DML command:

•INSERT
•UPDATE
•DELETE
•MERGE

INSERT = the INSERT statements adds new rows of data to the


table.

UPDATE = the UPDATE Statements modifies existing rows in the


table.

DELETE = The DELETE statements removes unwanted rows from


the table.
MERGE = The MERGE statements select rows from one table to
update or insert into another table .the decision whether to update
or insert into the target table is based on a conditions in the ON
clause .

CONTROLLING PL/SQL FLOW OF EXECUTION

You can change the logical execution of statement using


conditions IF statements and loop control structure

Conditions of IF statements:
•IF- THEN -END IF
•IF -THEN -ELSE- END- IF
•IF- THEN-ELSE- END- IF

IF STATEMENTS

SYNTAX

IF condition1 THEN
statement1;
ELSE
IF condition2 THEN
statement2;
ELSE
IF condition3 THEN
statement3;
END IF;
END IF;
END IF;

•CONDITION = Is a Boolean variable or expression (TRUE, FALSE , or


NULL).(It is a associate with a sequence of statement. which is
execute only if the expression yield TRUE)

•THEN = is a clause that associate the Boolean expression that


proceeds it with the sequence of statement that follows it.
•STATEMENT = can be one more PL/SQL or SQL statement ( they
may include further IF statement containing several nested IF
,ELSE, and ELSIF statement)

CREATING A PL/SQL RECORD

Records are another type of data types which oracle allows to be


defined as a placeholder. Records are a composite data type, which
means it is a combination of different scalar data types like char,
varchar, number etc. Each scalar data types in the record holds a
value. A record can be visualized as a row of data. It can contain all
the contents of a row.

Declaring a record:

To declare a record, you must first define a composite data type;


then declare a record for that type.

The General Syntax to define a composite data type is:


TYPE record_type_name IS
RECORD

(first_col_name
column_datatype,

second_col_name
column_datatype, ...);

•record_type_name – it is the name of the composite type you


want to define.
• first_col_name, second_col_name, etc.,- it is the names the
fields/columns within the record.
• column_datatype defines the scalar datatype of the fields.

CURSORS
An explicit cursor is defined in the declaration section of the PL/SQL
Block. It is created on a SELECT Statement which returns more than
one row. We can provide a suitable name for the cursor.

How to use Explicit Cursor?

There are four steps in using an Explicit Cursor.


• DECLARE the cursor in the declaration section.
• OPEN the cursor in the Execution Section.
• FETCH the data from cursor into PL/SQL variables or records in
the Execution Section.
• CLOSE the cursor in the Execution Section before you end the
PL/SQL Block.
Declaring a Cursor in the Declaration Section:

DECLARE

CURSOR emp_cur IS

SELECT *

FROM emp_tbl

WHERE salary > 5000;

How to access an Explicit Cursor?

These are the three steps in accessing the cursor.


1) Open the cursor.
2) Fetch the records in the cursor one at a time.
3) Close the cursor.
General Syntax to open a cursor is:
OPEN cursor_name;

General Syntax to fetch records from a cursor is:


FETCH cursor_name INTO record_name;

CLOSE cursor_name;

When a cursor is opened, the first row becomes the current row.
When the data is fetched it is copied to the record or variables and
the logical pointer moves to the next row and it becomes the
current row. On every fetch statement, the pointer moves to the
next row. If you want to fetch after the last row, the program will
throw an error. When there is more than one row in a cursor we can
use loops along with explicit cursor attributes to fetch all the
records.

What are Explicit Cursor Attributes?


Oracle provides some attributes known as Explicit Cursor Attributes
to control the data processing while using cursors. We use these
attributes to avoid errors while accessing cursors through OPEN,
FETCH and CLOSE Statements.

Exception Handling

What is Exception Handling?


PL/SQL provides a feature to handle the Exceptions which occur in a
PL/SQL Block known as exception Handling. Using Exception
Handling we can test the code and avoid it from exiting abruptly.
When an exception occurs a messages which explains its cause is
received.PL/SQL Exception message consists of three parts.

1) Type of Exception
2) An Error Code
3) A message

Structure of Exception Handling.


The General Syntax for coding the exception section
DECLARE

Declaration section

BEGIN

Exception section

EXCEPTION

WHEN ex_name1 THEN

-Error handling statements

WHEN ex_name2 THEN

-Error handling statements

WHEN Others THEN

-Error handling statements

END;
RAISE_APPLICATION_ERROR ( )
RAISE_APPLICATION_ERROR is a built-in procedure in oracle which is
used to display the user-defined error messages along with the error
number whose range is in between -20000 and -20999.
Whenever a message is displayed using
RAISE_APPLICATION_ERROR, all previous transactions which are not
committed within the PL/SQL Block are rolled back automatically
(i.e. change due to INSERT, UPDATE, or DELETE statements).
RAISE_APPLICATION_ERROR raises an exception but does not handle
it.
RAISE_APPLICATION_ERROR is used for the following reasons,
a) to create a unique id for an user-defined exception.
b) to make the user-defined exception look like an Oracle error.
The General Syntax to use this procedure is:
RAISE_APPLICATION_ERROR (error_number, error_message);

Exception Name Reason Error


Number
CURSOR_ALREADY_OP When you open a cursor ORA-06511
EN that is already open.

INVALID_CURSOR When you perform an ORA-01001


invalid operation on a
cursor like closing a cursor,
fetch data from a cursor
that is not opened.

NO_DATA_FOUND When a SELECT...INTO ORA-01403


clause does not return any
row from a table.

TOO_MANY_ROWS When you SELECT or fetch ORA-01422


more than one row into a
record or variable.

ZERO_DIVIDE When you attempt to divide ORA-01476


a number by zero.

Package

What Is a PL/SQL Package?


A package is a schema object that groups logically related PL/SQL
types, items, and subprograms. Packages usually have two parts, a
specification and a body, although sometimes the body is
unnecessary. The specification (spec for short) is the interface to
your applications; it declares the types, variables, constants,
exceptions, cursors, and subprograms available for use. The body
fully defines cursors and subprograms, and so implements the spec.
You can think of the spec as an operational interface and of the
body as a "black box." You can debug, enhance, or replace a
package body without changing the interface (package spec) to the
package.
Advantages of PL/SQL Packages

Modularity
Packages let you encapsulate logically related types, items, and
subprograms in a named PL/SQL module. Each package is easy to
understand, and the interfaces between packages are simple, clear,
and well defined. This aids application development.

Easier Application Design


When designing an application, all you need initially is the interface
information in the package specs. You can code and compile a spec
without its body. Then, stored subprograms that reference the
package can be compiled as well. You need not define the package
bodies fully until you are ready to complete the application.

Added Functionality
Packaged public variables and cursors persist for the duration of a
session. So, they can be shared by all subprograms that execute in
the environment. Also, they allow you to maintain data across
transactions without having to store it in the database.

Better Performance
When you call a packaged subprogram for the first time, the whole
package is loaded into memory. So, later calls to related
subprograms in the package require no disk I/O. Also, packages stop
cascading dependencies and thereby avoid unnecessary
recompiling. For example, if you change the implementation of a
packaged function, Oracle need not recompile the calling
subprograms because they do not depend on the package body.

Package
The package body implements the package spec. That is, the
package body contains the implementation of every cursor and
subprogram declared in the package spec. Keep in mind that
subprograms defined in a package body are accessible outside the
package only if their specs also appear in the package spec.
To match subprogram specs and bodies, PL/SQL does a token-by-
token comparison of their headers. So, except for white space, the
headers must match word for word. Otherwise, PL/SQL raises an
exception, as the following example shows:
CREATE PACKAGE emp_actions AS
...
PROCEDURE calc_bonus (date_hired emp.hiredate%TYPE, ...);
END emp_actions;

CREATE PACKAGE BODY emp_actions AS


...
PROCEDURE calc_bonus (date_hired DATE, ...) IS
-- Parameter declaration raises an exception because 'DATE'
-- does not match 'emp.hiredate%TYPE' word for word
BEGIN ... END;
END emp_actions;

The package body can also contain private


declarations, which define types and items necessary for the
internal workings of the package. The scope of these declarations is
local to the package body. Therefore, the declared types and items
are inaccessible except from within the package body. Unlike a
package spec, the declarative part of a package body can contain
subprogram bodies.

Overloading Packaged Subprograms

PL/SQL allows two or more packaged subprograms to have the


same name. This option is useful when you want a subprogram to
accept similar sets of parameters that have different data types. For
example, the following package defines two procedures
named journalize:

CREATE PACKAGE journal entries AS


...
PROCEDURE journalize (amount REAL, trans_date VARCHAR2);
PROCEDURE journalize (amount REAL, trans_date INT);
END journal_entries;

CREATE PACKAGE BODY journal_entries AS


...
PROCEDURE journalize (amount REAL, trans_date VARCHAR2) IS
BEGIN
INSERT INTO journal
VALUES (amount, TO_DATE(trans_date, 'DD-MON-YYYY'));
END journalize;

PROCEDURE journalize (amount REAL, trans_date INT) IS


BEGIN
INSERT INTO journal
VALUES (amount, TO_DATE(trans_date, 'J'));
END journalize;
END journal_entries;

Using the UTL_FILE Package

There have been many changes to the UTL_FILE package. These


include security enhancements using the CREATE DIRECTORY
statement, copying, deleting and renaming files, and handling raw
data.
In the latest release of 9i, the use of the UTL_FILE_DIR init.ora
parameter is advised against on security grounds. Because it is
possible to write programs to use this package and access the
directories set by utl_file_dir it is potentially possible to read files
and data you shouldn't be able to the advice now is to create a
directory and use that instead. By default, only SYS and SYSTEM
can create directories. We will examine the following new
capabilities

CREATE OR REPLACE PROCEDURE fcreate(loc_in IN


VARCHAR2,file_in IN VARCHAR2)
IS
fID UTL_FILE.FILE_TYPE;
BEGIN

fID:=UTL_FILE.FOPEN(loc_in,file_in,'W');

UTL_FILE.FCLOSE (fid);
END;

UTL_FILE.IS_OPEN =

CREATE OR REPLACE PROCEDURE utlfile_test


IS
v_filehandle UTL_FILE.FILE_TYPE;
v_newline VARCHAR2(1022);
BEGIN

IF NOT UTL_FILE.IS_OPEN(v_filehandle)THENv_newline:='This is
the lineof text';

END IF;

Oracle Supplied Packages

Package  Description

DBMS_ALERT
Notify a database event (asynchronous)

DBMS_APPLICATION_INFO
Register an application name with the database
For auditing or performance tracking.

V$SESSION/V$SESSION_LONGOPS
Application info can be pushed into

DBMS_AQ
Add a message (of a predefined object type) onto a queue
Or dequeue a message.

DBMS_AQADM
Administer a queue or queue table
For messages of a predefined object type.

DBMS_AQELM
Configure Advanced Queuing
Asynchronous notification by e-mail and HTTP. *

DBMS_BACKUP_RESTORE
Normalize filenames on Windows NT platforms.
DBMS_DDL
Access SQL DDL statements from a stored procedure,
Provides special administration operations
Not available as DDLs.

DBMS_DEBUG
Implement server-side debuggers and provide a way to
Debug server-side PL/SQL program units.

DBMS_DEFER
User interface to a replicated transactional deferred
RPC facility. Requires the Distributed Option.

DBMS_DEFER_QUERY
Permit querying the deferred remote procedure calls (RPC)
Queue data that is not exposed through views.
Requires the Distributed Option.

DMBS_DEFER_SYS
The system administrator interface to a replicated
Transactional deferred RPC facility.
Requires the Distributed Option.

DBMS_DESCRIBE
Describe the arguments of a stored procedure
With full name translation and security checking.

DBMS_DISTRIBUTED_TRUST_ADMIN
Maintain the Trusted Database List, which is used to
Determine if a privileged database link from a particular
Server can be accepted.

DBMS_ENCODE
Encode???

DBMS_FGA
Fine-grained security functions. *

DMBS_FLASHBACK
Flash back to a version of the database at a specified
Wall-clock time or a specified system change
Number (SCN). *

DBMS_HS_PASSTHROUGH
Send pass-through SQL statements to non-Oracle systems.
(Via Heterogeneous Services)

DBMS_IOT
Create a table into which references to the chained rows
For an Index Organized Table can be placed using the
ANALYZE command.

DBMS_JOB
Schedule PL/SQL procedures that you want performed at
Periodic intervals; also the job queue interface.

DBMS_LDAP
Functions and procedures to access data from
LDAP servers. *

DBMS_LIBCACHE
Prepares the library cache on an Oracle instance by
Extracting SQL and PL/SQL from a remote instance and
Compiling this SQL locally without execution. *

DBMS_LOB
General purpose routines for operations on Oracle Large
Object (LOBs) data types - BLOB, CLOB (read-write),
And BFILEs (read-only).

DBMS_LOCK
Request, convert and release locks through Oracle Lock
Management services.

DBMS_LOGMNR
Functions to initialize and run the log reader.

DBMS_LOGMNR_CDC_PUBLISH
Identify new data that has been added to, modified, or
Removed from, relational tables and publish the changed
Data in a form that is usable by an application. *

DBMS_LOGMNR_CDC_SUBSCRIBE
View and query the change data that was captured
And published with the DBMS_LOGMNR_CDC_PUBLISH package. *
DBMS_LOGMNR_D
Query the dictionary tables of the current database, and
Create a text based file containing their contents.

DBMS_METADATA
Retrieve complete database object definitions (metadata)
From the dictionary. *

DBMS_MVIEW
Refresh snapshots that are not part of the same
Refresh group and purge logs. DBMS_SNAPSHOT is a synonym.

DBMS_OBFUSCATION_TOOLKIT
Procedures for Data Encryption Standards.

DBMS_ODCI
Get the CPU cost of a user function based on the
Elapsed time of the function. *

DBMS_OFFLINE_OG
Public APIs for offline instantiation of master groups.

DBMS_OFFLINE_SNAPSHOT
Public APIs for offline instantiation of snapshots.

DBMS_OLAP
Procedures for summaries, dimensions, and query rewrites.

DBMS_ORACLE_TRACE_AGENT
Client callable interfaces to the Oracle TRACE
Instrumentation within the Oracle7 Server.

DBMS_ORACLE_TRACE_USER
Public access to the Oracle release 7 Server
Oracle TRACE instrumentation for the calling user.

DBMS_OUTLN
Interface for procedures and functions associated with
Management of stored outlines. Synonymous with OUTLN_PKG

DBMS_OUTLN_EDIT
Edit an invoker's rights package. *
DBMS_OUTPUT
Accumulate information in a buffer so that it can be
Retrieved out later.

DBMS_PCLXUTIL
Intra-partition parallelism for creating partition-wise
Local indexes.

DBMS_PIPE
A DBMS pipe service which enables messages to be sent
Between sessions.

DBMS_PROFILER
A Probe Profiler API to profile PL/SQL applications
And identify performance bottlenecks.
To install this run profload.sql(as SYS) and proftab.sql(as user)

DBMS_RANDOM
A built-in random number generator.
Options to generate random numbers within a range or distribution.

DBMS_RECTIFIER_DIFF
APIs used to detect and resolve data inconsistencies
Between two replicated sites.

DBMS_REDEFINITION
Reorganize a table (change it's structure) while it's
Still online and in use. *

DBMS_REFRESH
Create groups of snapshots that can be refreshed together
to a transitionally consistent point in time.
Requires the Distributed Option.

DBMS_REPAIR
Repair data corruption.

DBMS_REPCAT
Administer and update the replication catalog and environment.
Requires the Replication Option.

DBMS_REPCAT_ADMIN
Create users with the privileges needed by the symmetric
replication facility. Requires the Replication Option.

DBMS_REPCAT_INSTATIATE
Instantiates deployment templates.
Requires the Replication Option.

DBMS_REPCAT_RGT
Define and maintain refresh group templates.
Requires the Replication Option.

DBMS_REPUTIL
Generate shadow tables, triggers, and packages
For table replication.

DBMS_RESOURCE_MANAGER
Maintain plans, consumer groups, and plan directives;
Also provides semantics so that you may group together
Changes to the plan schema.

DBMS_RESOURCE_MANAGER_PRIVS
Maintain privileges associated with resource consumer groups.

DBMS_RESUMABLE
Suspend large operations that run out of space or reach space
Limits after executing for a long time, fix the problem, and
Make the statement resume execution.

DBMS_RLS
Row level security administrative interface.

CHAPTER 4

TECHNOLOGY DETAILS

4.1 THE ORIGINS OF PL/SQL


Oracle has a history of leading the software industry in providing
declarative, nonprocedural approaches to designing both databases
and applications. The Oracle Server technology is among the most
advanced, powerful, and stable relational databases in the world. Its
application development tools, such as Oracle Forms, offer high
levels of productivity, precisely by relying heavily on a "paint-your-
screen" approach in which extensive default capabilities allow
developers to avoid heavy customized programming efforts.

In Oracle's early years, this declarative approach, combined with its


groundbreaking relational technology, was enough to satisfy
developers. But as the industry matured, expectations and
requirements became more demanding. Developers needed to get
under the skin of the products. They needed to build complicated
formulas, exceptions, and rules into their forms and database
procedures.

In 1991, Oracle Corporation released Oracle Version 6.0, a major


advance in its relational database technology. A key component of
Oracle Version 6.0 was the so-called "procedural option" or PL/SQL.
At roughly the same time, Oracle released its long-awaited upgrade
to SQL*Forms Version 2.3. SQL*Forms V3.0 incorporated the PL/SQL
engine for the first time on the tool side, allowing developers to
code their procedural logic in a natural, straightforward manner.

This first release of PL/SQL was very limited in its capabilities. On


the server side, you could use PL/SQL only to build "batch-
processing" scripts of procedural and SQL statements. In other
words, you could not store procedures or functions for execution at
some later time. You could not construct a modular application or
store complex business rules in the server. On the client side,
SQL*Forms V3.0 did allow you to create procedures and functions,
though support for functions was not documented and therefore not
used by many developers for years. In addition, this release of
PL/SQL did not implement array support and could not interact with
the operating system (for input or output). It was a far cry from a
full-fledged programming language.
For all its limitations, PL/SQL was warmly, even enthusiastically,
received in the developer community. The hunger for the ability to
code a simple IF statement inside SQL*Forms was strong. The need
to perform multi-SQL statement batch processing was
overwhelming.

What few developers realized at the time was that the original
motivation and driving vision behind PL/SQL extended beyond the
desire to offer programmatic control within products like
SQL*Forms. Very early in the life cycle of Oracle's database and
tools, Oracle Corporation had recognized two key weaknesses in
their architecture: lack of portability and problems with execution
authority.
4.1.1 Improved Application Portability with PL/SQL
The concern about portability might seem odd to those of us
familiar with Oracle Corporation's marketing and technical
strategies. One of the hallmarks of the Oracle solution from the
early 1980s was its portability. At the time that PL/SQL came along,
the C-based RDBMS ran on many different operating systems and
hardware platforms.

SQL*Plus and SQL*Forms adapted easily to a variety of terminal


configurations. Yet for all that coverage, there were still many
applications which needed the more sophisticated and granular
control offered by host languages like COBOL, C, and FORTRAN. As
soon as a developer stepped outside of the port-neutral Oracle
tools, the resulting application would no longer be portable.

The PL/SQL language was (and is) intended to widen the range of
application requirements which can be handled entirely in
operating-system independent programming tools.

4.1.2 Improved Execution Authority and Transaction


Integrity with PL/SQL
Even more fundamental an issue than portability was that
of execution authority. The RDBMS and SQL language give
you the capability to tightly control access to and changes
in, any particular table. For example, with the GRANT
command you can make sure that only certain roles and
users have the ability to perform an UPDATE on a given
table. On the other hand, this GRANT statement can't
ensure that the full set of Updates performed by a user or
application is done correctly. In other words, the database
can't guarantee the integrity of a transaction that spans
more than one table.
Let's look at an example. In a typical banking transaction,
you might need to transfer funds from account A to
account B. The balance of account B must be incremented,
and that of account A decremented.

Table access is necessary, but not sufficient, to guarantee


that both of these steps are always performed by all
programmers who write code to perform a transfer. Without
stored objects, the best you can do is require extensive
testing and code review to make sure that all transactions
are properly constructed. With stored objects, on the other
hand, you can guarantee that a funds transfer either
completes successfully or is completely rolled back --
regardless of who executes the process.

The secret to achieving this level of transaction integrity is


the concept of execute authority (also known as run
authority). Instead of granting to a role or user the
authority to update a table, you grant privileges to only
execute a procedure. This procedure controls and provides
access to the underlying data structures. The procedure is
owned by a separate Oracle RDBMS account, which, in
turn, is granted the actual update privileges on those
tables needed to perform the transaction. The procedure
therefore becomes the "gatekeeper" for the transfer
transaction. The only way a program (whether it's an
Oracle Forms application or a Pro*C executable) can
execute the transfer is through the procedure. The result is
that transaction integrity is guaranteed.

The long-term objective of PL/SQL, realized with PL/SQL


Version 2.0, was to provide a programming environment
which would allow developers both to create reusable,
callable modules and also to grant authority to those
modules. Given Oracle Corporation's strategic technical
investment in relational databases, it's only logical that
these programs would reside in the database itself. This
way, the same data dictionary that controls access to data
could control access to the programs.

PL/SQL has come a long way from its humble beginnings. It


is a rapidly maturing programming language that will play
a prominent role in all future Oracle application
development and database management efforts.
4.2 PL/SQL VERSIONS
One thing that may complicate using PL/SQL is that it is not
a single product. There are several distinct, supported
versions out there. Table summarizes the various versions;
the following sections describe the main features available
in each of the versions in use today.

Table 1.2: PL/SQL Versions

Version/Release & Characteristics

Version 1.0
First available in SQL*Plus as a batch-processing script.
Oracle Version 6.0 was released at approximately the same
time. PL/SQL was then implemented
within SQL*Forms Version 3, the
predecessor of Oracle Forms.

Release 1.1
Available only in the Oracle Developer/2000 Release 1 tool
this upgrade supports client-side packages and allows
client-side programs to execute stored code transparently.

Version 2.0
Available with Release 7.0 (Oracle Server).Major upgrade to
Version 1. Adds support for stored procedures, functions,
packages, programmer-defined records, PL/SQL tables, and
many package extensions, including DBMS_OUTPUT and
DBMS_PIPE.

Release 2.1
Available with Release 7.1 of the Oracle Server Version.
Supports programmer-defined subtypes, enables the use of
stored functions inside SQL statements, and offers dynamic
SQL with the DBMS_SQL package. With Version 2.1, you can
now execute SQL DDL statements from within PL/SQL
programs.

Release 2.2
Available with Release 7.2 of the Oracle Server Version.
Implements a binary "wrapper" for PL/SQL programs to
protect source code, supports cursor variables for
embedded PL/SQL environments such as Pro*C, and makes
available database-driven job scheduling with the
DBMS_JOB package.

Release 2.3
Available with Release 7.3 of the Oracle Server Version.
Enhances functionality of PL/SQL tables, offers improved
remote dependency management, adds file I/O capabilities
to PL/SQL, and completes the implementation of cursor
variables.
Chapter 6
Conclusion & Result:
After completion of this practical training I conclude that
training in the Engineering is an essential task for each and
every student and it must be taken seriously.
The practical training is a chance to the trainee to gain the
practical knowledge in the field and to work in the
scheduled environment. Apart from these things it
improves the managing qualities, which are essential for an
engineer.
It is very fruitful experience for me to overcome my
weaknesses and how to face and solve the difficulties
arises in the field.
Table of Contents
Topics Page No .

Acknowledgments………………………………….…1

Description……………………………………………..4

Chapter 1: Introduction………..……………….….5

Chapter 2: Technical Details………………………6

Chapter 3: Manipulating Data using PL/SQL.18


Chapter 4:Packages………….……....................25

Chapter 5: Technology Details........................35

Chapter 6: Result and Conclusion…………..…41

Das könnte Ihnen auch gefallen