You are on page 1of 10

INTRODUCTION TO PL/SQL

INTRODUCTION TO PL/SQL

Objectives
At the end of the unit, you will be able to De!"#ibe the featu#e! and ad$anta%e! of PL/SQL& 'ind out the en$i#on(ent! whe#e PL/SQL i! a$ailable& Li!t the )#o%#a( "on!t#u"t! that "an be built f#o( a PL/SQL blo"*&

Topics
Int#odu"tion PL/SQL

INTRODUCTION TO PL/SQL

Introduction
PL/SQL i! a de$elo)(ent tool whi"h allow! you to u!e the fa"ilitie! of O#a"le!,! SQL databa!e lan%ua%e& PL/SQL i! the P#o"edu#al lan%ua%e e-ten!ion to the SQL& It "an "ontain any nu(be# of SQL data (ani)ulation/$alidation !tate(ent!, t#an!a"tion )#o"e!!in% and the "u#!o# "ont#ol o)e#ation!& It )#o$ide! )#o"edu#al te"hni.ue! li*e loo)in% and b#an"hin% to anothe# blo"* of "ode& /hy PL/SQL0 SQL i! a non1)#o"edu#al lan%ua%e& The databa!e !e#$e# i! told to do !o(ethin%, not how to do it& The databa!e !e#$e# t#an!late! the SQL "o((and! into inte#nal )#o"edu#e! to )#o"e!! the #e.ue!t& SQL i! ea!y to u!e a! it hide! the detail! of data )#o"e!!in%& P#o"edu#al lan%ua%e! #e.ui#e you to *now how to a""e!! data and "#eate )#o%#a(! u!in% a $e#y !t#u"tu#al de!i%n& Althou%h a )#o"edu#al lan%ua%e i! (o#e diffi"ult to u!e than a non1)#o"edu#al lan%ua%e, it offe#! (o#e fle-ibility 2 )owe#& To (e#%e the ad$anta%e! of )#o"edu#al 2 non1)#o"edu#al lan%ua%e!, ORACL3 4 offe#! )#o"edu#al lan%ua%e! e-ten!ion to SQL "alled PL/SQL& PL/SQL i()#o$e! a))li"ation and !y!te( )e#fo#(an"e be"au!e 5 Rathe# than un"o()iled SQL !tate(ent!, fa!t1e-e"utin% "o()iled )#o%#a(! a#e u!ed& Netwo#*in% t#affi" between the "lient 2 !e#$e# "an be #edu"ed&

INTRODUCTION TO PL/SQL

SQL and PL/SQL a#e u!ed to "o((uni"ate with O#a"le databa!e f#o( an a))li"ation& 'ollowin% )i"tu#e e-)lain! the databa!e o)e#ation! )e#fo#(ed with SQL&
Se#$e#

O#a"le

SQL

SQL

SQL

A))li"ation

'i%u#e 1 5 Databa!e o)e#ation! )e#fo#(ed with SQL&

INTRODUCTION TO PL/SQL

I!!ue a PL/SQL 8lo"* 'ollowin% )i"tu#e e-)lain! the databa!e o)e#ation! )e#fo#(ed with PL/SQL&

Se#$e#

O#a"le

PL/SQL 8LOC: SQL I' ; T<3N SQL 3LS3 SQL 3ND I'

A))li"ation 'i%u#e + 5 Databa!e o)e#ation! )e#fo#(ed with PL/SQL&

INTRODUCTION TO PL/SQL

PL/SQL
PL/SQL i! O#a"le,! )#o"edu#al lan%ua%e e-ten!ion to SQL& PL/SQL allow! you to (i- SQL !tate(ent! with )#o"edu#al "on!t#u"t!& PL/SQL )#o$ide! the "a)ability to define and e-e"ute PL/SQL )#o%#a( unit! !u"h a! )#o"edu#e!, fun"tuion! and )a"*a%e!& PL/SQL )#o%#a( unit! %ene#ally a#e "ate%o#i=ed a! anony(ou! blo"*! and !to#ed )#o"edu#e!& An anony(ou! blo"* i! a PL/SQL blo"* that a))ea#! within you# a))li"ation and it i! not na(ed o# !to#ed in the databa!e& In (any a))li"ation!, PL/SQL blo"*! "an a))e# whe#e$e# SQL !tate(ent! "an a))ea#& A !to#ed )#o"edu#e i! a PL/SQL blo"* that O#a"le !to#e! in the databa!e and "an be "alled by na(e f#o( an a))li"ation& /hen you "#eate a !to#ed )#o"edu#e, O#a"le )a#!e! the )#o"edu#e and !to#e! it! )a#!ed #e)#e!entation in the databa!e& PL/SQL en%ine i! a !)e"ial "o()onent of (any O#a"le )#odu"t! in"ludin% the O#a"le !e#$e# that )#o"e!!e! PL/SQL& The )#o"edu#e>o# )a"*a%e? i! !to#ed in a databa!e& /hen an a))li"ation "all! a )#o"edu#e !to#ed in a databa!e& O#a"le load! the "o()iled )#o"edu#e >o# )a"*a%e? into the !ha#ed )ool in the S@A& And the PL/SQL and SQL !tate(ent e-e"uto#! wo#* to%ethe# to )#o"e!! the !tate(ent! within the )#o"edu#e& The followin% O#a"le )#odu"t! "ontain a PL/SQL en%ine O#a"le Se#$e# O#a"le 'o#(!>Ae#!ion 6 and late#? O#a"le Re)o#t! >Ae#!ion + and late#? O#a"le @#a)hi"! >Ae#!ion + and late#?

A !to#ed )#o"edu#e "an be "alled f#o( anothe# PL/SQL blo"*, whi"h "an be eithe# an anony(ou! blo"* o# anothe# !to#ed )#o"edu#e&

INTRODUCTION TO PL/SQL

8a!i" PL/SQL 8lo"* St#u"tu#e PL/SQL i! a blo"*1!t#u"tu#ed lan%ua%e& In a !in%le PL/SQL )#o%#a(, #elated !et! of !tate(ent! "an be %#ou)ed in blo"*ed fo# ea!ie# )#o%#a((in% and #eadability& D3CLAR3

83@IN

3CC3PTION

3ND

In the abo$e e-a()le PL/SQL )#o%#a( ha! 6 blo"*! The D3CLAR3 blo"* i! the !e"tion whe#e "on!tant!, $a#iable! , and u!e#1defined data ty)e! that a#e to be u!ed in the )#o%#a( body a#e de"la#ed& The 83@IN !tate(ent (a#*! the be%innin% of the (ain )#o%#a( body& The 3CC3PTION blo"* i! whe#e e-"e)tion handle#! to handle e##o# "ondition! a#e w#itten& The 3ND !tate(ent indi"ate! end of the (ain )#o%#a( body& /ithin the (ain )#o%#a( blo"*, any nu(be# of ne!ted blo"*! ea"h !ta#tin% with a 83@IN !tate(ent endin% with an 3ND !tate(ent (ay e-i!t& All !tate(ent! end with a !e(i"olon& Co((ent! a#e en"lo!ed within /D D/ o# )#e"eded by 11&

INTRODUCTION TO PL/SQL

Oracle Server

Databa!e A))li"ation

S@A P#o"edu#e 8e%in P#o"edu#al P#o"edu#al SQL P#o"edu#al SQL 3nd F

PL/SQL 3n%ine P#o"edu#al !tate(ent e-"e"uto#

P#o%#a( "ode P#o%#a( "ode P#o"edu#e "all P#o%#a( "ode P#o%#a( "ode

SQL State(ent 3-e"uto#

Databa!e

'i%u#e 6 5 The PL/SQL 3n%ine and the O#a"le Se#$e#&

INTRODUCTION TO PL/SQL

Advantages
A))li"ation Pe#fo#(an"e /ithout PL/SQL the SQL !tate(ent! a#e )#o"e!!ed one at a ti(e, whi"h !low! down the table data )#o"e!!in% "on!ide#ably& /ith PL/SQL, the enti#e blo"* i! !ent fo# )#o"e!!in% to the RD8GS en%ine, #e!ultin% in a (u"h fa!te# e-e"ution of the "ode& Po#tability PL/SQL "ode w#itten fo# a DOS $e#!ion will ea!ily #un on the UNIC $e#!ion& P#o%#a((in% 3n$i#on(ent P#o%#a(! "an be w#itten fo# $alidation! and (ani)ulation!, e##o# handlin% #outine! et"&, u!in% the PL/SQL& The PL/SQL Program Constructs

Anony(ou! 8lo"* 'o#(! T#i%%e# !

Sto#ed P#o"edu#e/'un"tio n

D3CLAR3

83@IN

3CC3PTION

3ND Databa! e T#i%%e#! Pa"*a%ed P#o"edu#e 'o#(! P#o"edu#e/'un"tion

INTRODUCTION TO PL/SQL

Summary !
8a!e the !t#u"tu#e of all PL/SQL )#o%#a( "on!t#u"t! u)on the ba!i" PL/SQL blo"*& PL/SQL 8lo"* St#u"tu#e Se"tion De"la#ation Se"tion 3-e"utable Se"tion 3-"e)tion <andlin% De!"#i)tion Contain! all $a#iable!, "on!tant!, "u#!o#!, and U!e# defined e-"e)tion! that will be #efe#en"ed within the 3-e"utable Se"tion& Contain! SQL !tate(ent! to (ani)ulate data in the databa!e, and PL/SQL !tate(ent! to (ani)ulate data in the blo"*& S)e"ifie! the a"tion! to )e#fo#( when e##o#! and abno#(al "ondition! a#i!e within the 3-e"utable Se"tion& In"lu!ion O)tional Gandato#y O)tional

8uild a $a#iety of diffe#ent PL/SQL )#o%#a( "on!t#u"t! with the ba!i" PL/SQL blo"*, de)endin% u)on thei# u!e and a$ailability& PL/SQL P#o%#a( Con!t#u"t! P#o%#a( De!"#i)tion Con!t#u"t! Anony(ou! Unna(ed PL/SQL blo"* that i! 8lo"* e(bedded within an a))li"ation o# i! i!!ued inte#a"ti$ely& Sto#ed Na(ed PL/SQL blo"* that "an P#o"edu#e/' a""e)t )a#a(ete#! and "an be un"tion in$o*ed #e)eatedly O#a"le Na(e! PL/SQL blo"* that "an 'o#(! a""e)t )a#a(ete#! and "an be P#o"edu#e!/ in$o*ed #e)eatedly fun"tion! Pa"*a%e Na(ed PL/SQL (odule that %#ou)! to%ethe# #elated )#o"edu#e!, fun"tion!, and identitie!& Databa!e PL/SQL blo"* that i! a!!o"iated T#i%%e# with a databa!e table and i! fi#ed auto(ati"ally O#a"le PL/SQL blo"* that i! a!!o"iated 'o#(! with an O#a"le 'o#(! e$ent and i! t#i%%e# fi#ed auto(ati"ally A$ailability All PL/SQL 3n$i#on(ent! The O#a"le 4 Se#$e# with P#o"edu#al O)tion O#a"le fo#(!

The O#a"le 4 Se#$e# with P#o"edu#al O)tion The O#a"le Se#$e# with the P#o"edu#al O)tion O#a"le 'o#(!

1I

You might also like