Sie sind auf Seite 1von 3

Introduction to PL/SQL

______________________

1.
What is a PL/SQL
****************

PL/SQL stands for Procedural Language extension of SQL.


PL/SQL is a combination of SQL along with the procedural features of programming
languages.
It was developed by Oracle Corporation in the early 90's to enchance the
capabilities of SQL.

*************************************************

*************************************************

2.
About PL/SQL
************

PL/SQL :
1.Provides a Block structure for executable units of code.
2.Provides procedural constructs such as :
- Variables,constants and types
- Control structures such as conditional statements and loops
- Resuable program units that are written once and executed many times.

*************************************************

*************************************************

3.
PL/SQL Environment
******************

A PL/SQL Block contains procedural statements and SQL statements.


When you submit the PL/SQL Block to the server the PL/SQL engine first parses the
block.
The PL/SQL Engine identifies the procedural statements and SQL statements.
It passes the procedural statements to the procedural statement executor and passes
the SQL statement to the SQL statement executor individually.
During execution of Pl/Sql Program to execute all procedural statements (like if,
for, assignments...) Oracle uses
Pl/Sql engine and sends all SQL statements present in the code to the SQL engine.
The SQL engine will parse and execute the query or DML statement and return the
expected output back to the PL/SQL engine. This switch between the two engines is
called context switching.

*************************************************

*************************************************

4.
Benefits of PL/SQL
******************
1.Integration
of procedural constructs with SQL
2.Improved Performance
3.Modularized program development
4.Integration with Oracle Tools
5.Portability
6.Exception Handling

*************************************************

*************************************************

5.
PL/SQL Block Structure
**********************

DECLARE (Optional)
-- Variables,cursors,user-defined exceptions
BEGIN (Mandatory)
-- SQL Statements
-- PL/SQL Statements
EXCEPTION (Optional)
-- Actions to perform when errors occur
END (Mandatory)

*************************************************

*************************************************

6.
Block Types
***********

There are three types of blocks in PL/SQL :


1.Anonymous Blocks
2.Procedures
3.Function

1.Anonymous Blocks are unnamed blocks.These blocks are not stored in the database.
They are passed to the PL/SQL engine for execution at run time.
If you want to execute the same block again you have to rewrite the block.

2.Subprograms are complementary to anonymous blocks.They are named PL/SQL blocks


that are stored in the database.Because they are named and stored you can invoke
them whenever you want.
You can declare them either as a procedure or a function.
You use a Procedure to perform an action and a function to compute and return a
value.

*************************************************

*************************************************

7.
Program Constructs
******************

Tools Constructs :
1.Anonymous Block
2.Application procedures or functions
3.Application packages
4.Application triggers
5.Object types

Database Server Constructs


1.Anonymous Block
2.Stored procedures or functions
3.Stored packages
4.Database Triggers
5.Object Types

*************************************************

*************************************************

8.
Create an Anonymous Block
*************************

Example to display the text 'Welcome to PL/SQL Programming'

BEGIN
DBMS_OUTPUT.PUT_LINE('Welcome to PL/SQL Programming');
END;
/

*************************************************

*************************************************

9.
Test the Output of a PL/SQL Block
*********************************

1.Enable the output using the command


SET SERVEROUTPUT ON
2.Use a predefined Oracle Package and its procedure
DBMS_OUTPUT.PUT_LINE('Output');

So in the previous example modify the PL/SQL Block

-- First enable the Output --


SET SERVEROUTPUT ON

BEGIN
DBMS_OUTPUT.PUT_LINE('Welcome to PL/SQL Programming');
END;
/

*************************************************

*************************************************

Das könnte Ihnen auch gefallen