Sie sind auf Seite 1von 4

PL/SQL Topics:

-------------Introduction PL/SQL
Basics PL/SQL
PL/SQL Data Types
PL/SQL Condition Looping Sequential Case
PL/SQL Conditional Control
PL/SQL Loop Statement
PL/SQL Case Statement
PL/SQL Sequential Control
PL/SQL Transaction Cursor Exception
PL/SQL Transaction
PL/SQL Cursors
PL/SQL Exception
Advance PL/SQL
PL/SQL
PL/SQL
PL/SQL
PL/SQL

Procedures
Functions
Packages
Triggers

Introduction To PL/SQL:
PL/SQL(Procedural Language/Structured Query Language):
-----------------------------------------------------"PL/SQL is the procedural extention to Structured Query Language
(SQL) with design features of programming languages."
Data manipulation and query statements of SQL are included with
in procedural units of code.
PL/SQL is specially designed for Database oriented activities.
Oracle PL/SQL allows you to perform data manipulation operation
those are safe and flexible.
"PL/SQL includes procedural language elements (like declaration,
conditions,looping) and
also we can able to handle a runtime exception".
PL/SQL Environment
PL/SQL engine
PL/SQL
PL/SQL Block -----> PL/SQL block ---------> Procedural
Statement Executor
|
|SQL
|
W
SQL Statement Ex
ecutor
Oracle S
erver

Keywords In PL/SQL:
------------------The basic structure block of PL/SQL is built using following key
words
DECLARE
BEGIN
EXCEPTION(optional)
END
Blocks In PL/SQL:
----------------PL/SQL is a modualized program development.The above keywords ar
e arranged in different blocks they are as follows
Declaration Block (DECLARE)
Executable Block (BEGIN)
Exception Handling Block (EXCEPTION)
End Block (END)
Blocks of PL/SQL code are passed and processed at PL/SQL engine.
Sub programs are named as PL/SQL blocks, declared as either proc
edures or functions.
NOTE: You can invoke sub programs from different environments.

Advantages of PL/SQL:
-------------------PL/SQL is a very secure functionality tool for manipulating,controlling,validati
ng and resctricting unauthorized
access data from the SQL database.
Using PL/SQL we can improve application performance. It also allows to deal with
errors so we can provide user
friendly error messages.
PL/SQL have a great functionality to display multiple records from the multiple
tables at the same time.
PL/SQL is capable to send entire block of statements and execute it in the Oracl
e engine at once.
Some more advantages of PL/SQL
1.Procedural Language Support: Development tool for manipulation future,conditio
nal checking,looping or branching operations. Same as like other programming lan
guage.
2.Reduces Network Traffic: PL/SQL nature is entire block of SQL statements execu
te in to oracle engine all at once so it is main benefit is reducing the network
traffic.
3.Error Handling: PL/SQL permits the smart way of handling errors and giving use
r friendly error messages,when errors are encountered.
4.Declare Variable: PL/SQL gives u control to declare variables and access them
with in the block. The declared variables can be used at the time by query proce
ssing.
5.Intermediate Calculation: Calculations in PL/SQL done quickly and efficiently
with out using Oracle engines. This improves the transactional performance.
6.Portable Application: Applications written in PL/SQL are portable in any Opera
ting System.

Basics PL/SQL:
=============
PL/SQL Block Structure:
PL/SQL is block structured language divided in to three
logical blocks.
BEGIN block and END; keyword are compulsory and other tw
o block DECLARE and EXCEPTION are optional blocks.
END; is not a block only keyword to end of PL/SQL progra
m.
PL/SQL block structure follows divide-and-conquer approach to so
lve the problem stepwise.
DECLARE(Optional)
Declaration of Variables,Constan
ts.
BEGIN
PL/SQL Executable Statements.
EXCEPTION(Optional)
PL/SQL Exception Handler Block.
END;
DECLARE:
Variables and Constants are declared,initialized
with in this section.
BEGIN:
BEGIN block is procedural statement block which
will implement the actual programming logic. This section contains conditional s
tatements(if...else),looping statements(for,while) and Branching Statements(goto
) etc.
EXCEPTION:
PL/SQL easily detects user defined or predefined
error condition.
PL/SQL is famous for handling errors in smart wa
y by giving suitable
user friendly messages.
Errors can be raised due to wrong syntax, bad lo
gical or not passing a validation rules.
Userdefined Exception:
You can also define exception in your de
clarative block and later
you can execute it by RAISE statement.
NOTE: 1.BEGIN block and END; keywords are compulsory of any PL/S
QL program.
2.Where as DECLARE and EXCEPTION block are optional.
Example PL/SQL Program:
Example 1:
DECLARE
tialize values

--DECLARE block ,declare and in

designation VARCHAR2(30);
empNo CONSTANT NUMBER(5) := 5;
id BOOLEAN;
inter INTERVAL YEAR(2) TO MONTH;
check_exist EXCEPTION;
BEGIN

--BEGIN block, also assigns valu

es
designation := UPPER('Web Developer');
id := TRUE;
inter := INTERVAL '45' YEAR;
RAISE check_exist;
EXCEPTION
WHEN check_exist THEN
dbms_output.put_line('Some error occured
. Please check the PL/SQL block once.')
--execute raise exception or handle exce
ption.
END;
/
NOTE 1: Generally slash(/) is used to re-execute
the command in the buffer in case of SQL.
NOTE 2: Generally slash(/) is used to execute th
e block in PL/SQL. Other wise PL/SQL Engine will wait for the next line of code.
Example 2:
DECLARE
description VARCHAR2(20);
age CONSTANT NUMBER(5):=22;
BEGIN
description := 'Web Developer';
dbms_output.put_line('I am' || descripti
on || 'and I am '|| ages || 'years Old.');
END;
/
PL/SQL Data Types:
=================

Das könnte Ihnen auch gefallen