Вы находитесь на странице: 1из 6

PL/SQL DOCUMENTATION 1. EXPLAIN PL/SQL, PL/SQLBLOCK?

PL/SQL is a procedural language that has both interactive SQL and procedural language constructs such as iterations, conditional branching. PL/SQL block is a block-structured language. Each block is supposed to perform one logical unit of ob. 2. MAIN BLOCKS OF PL/SQL? PL/SQL block is having ! parts "eclaration part E#ecutable part E#ception handling part Declarati ! "art# PL/SQL enforces the declaration of variables before their use in e#ecutable portion. $ll variables %or& constants have to be declared in this block. S'nta#( variable name data t'pe) E$ec%ta&le "art# this is main section of the block, all the procedural and SQL statements are defined here. E$ce"ti ! 'a!(li!) "art# this is used for responding to runtime errors encountered b' a program. MANDATO*+ BLOCKS IN PL/SQL# e#ecutable block in PL/SQL is the mandator' block other t*o blocks declarative and e#ception blocks are optional blocks. ,. -.AT IS NAMED BLOCK? +amed blocks are the blocks that have a name associated *ith ! t'pes Labeled blocks( blocks *ith a label that gives the block name. Sub program( consists of procedures and functions. ,riggers( consists of pl/s-l block that is associated *ith an event that occurs in the database. /. -.AT IS ANON+MOUS BLOCK? ,hese blocks are generall' constructed d'namicall' and e#ecute onl' once. .lock is often issued from a client program to call a sub program in the database. 0. EXPLAIN 1 T+PE, 1*O-T+PE IN PL/SQL? 1 T+PE# it is used to give data t'pe of predefined variable and database column. E#( declare /tem code number %10&) / code item code1 t'pe) 1*O-T+PE# it is used to provide record data t'pe to a variable. ,he variable can stop ro* of the table %or& ro* fetched from the cursor. 2. DATA T+PES IN PL/SQL? Scalar data t'pe( number, character, .oolean, date/time. 2omposite data t'pe( table, record. 3eference data t'pe( ref cursor.

Lob t'pes( %large ob ects&

.file %variable stores locator of the file& .Lob %for storing large ra* data like graphics or sound data& 2lob%stores location, *hich provides location of data&

3. EXPLIAIN PL/SQL TABLES, 4A**A+S, NESTED TABLES? PL/SQL TABLES# ,hese are temporar' arra' like ob ects used in pl/s-l block. ,hese can have one column 4 a primar' ke'. ,hese are declared in the declarative part of an' block, sub Program or Package. S5!ta$# S,EP1( t'pe5name of t'pe6 is table of5col def6 inde# b' binar'-integer) S,EP7( 5pl/s-l-tablename6 5t'pe name6) NESTED TABLES# Similarl' to PL/SQL block along *ith adding the abilit' to store +ested tables *ithin a database table *ill be there. S5!ta$# t'pe table name is table of table t'pe) 4A**A+S# 8arra' are implemented differentl', elements are inserted into varra' starting at inde#1 upto ma#imum length declared in the varra'. S5!ta$# t'pe t'pe-name is varra' %ma#-si9e& of element-t'pe %not null&) 6. EXPLAIN AUTONOMOUS T*ANSACTION, *EST*ICT7*EFE*ENCE AND EXCEPTION7INIT? AUTONOMOUS T*ANSACTION( /t is used *hen ever in a transaction *ith in another transaction should be committed or rollback irrespective of parent transaction commit or rollback. *EST*ICT7*EFE*ENCE( /t is used to assert the purit' level for the user-defined functions. S5!ta$# P3$:;$ 3ES,3/2,-3E<E3E+2ES %function-name, =rnds>, =*nds>, =rnps>, =*nps>& EXCEPTION7INIT# used for associating a named e#ception *ith in a particular oracle error S5!ta$# P3$:;$ E?2EP,/@+-/+/, %e#ception-name, oracle error number& 89. -.AT IS P*A:MA? Pragmas are compiler directives) it serves as instructions to the pl/s-l compiler. ,he compiler *ill act on the pragma during the compilation of the block. 88.-.AT IS EXCEPTION .ANDLIN: IN PL/SQL; T+PES OF EXCEPTION? E#ception handling is used to handle the errors according to users *a' and functions /t *ill be used to generate error messages and replacing default messages. ,hese are 7 t'pes standard 4 user defined e#ceptions. STANDA*D EXCEPTIONS 9* BUILT IN EXCEPTIONS# 7

@racle package standard had defined e#ceptions for certain common errors Some of them are( ,oo-man'-ro*s %ora-01A77& +o-data-found %ora-1A0!& 8alue-error %ora-0BC07& Dero-divide %ora-01AEB& /nvalid-number %ora-01E77& "up-value-on-inde# %ora-00001& Program-error %ora-0BC01& USE* DEFINED EXCEPTIONS# ,he user defines these e#ceptions and these are used to take care of abnormal conditions that are application specific. 82. EXPLAIN SQL CODE ; SQLE**M? ,hese are functions, *hich return error code and error message of the recent error. SQL CODE# it returns error code as negative number. <or +@-"$,$-<@F+" it returns GH100I. SQL E***M# it returns length of the messages in C17 characters, *hich includes code, message, and tablename4column name. S'nta#( ercode( Js-lcode) Er msg( Js-lerrm) /nsert into error table values %errcode, ermsg&) 8,. -.AT IS *AISE7APPLICATION7E**O*? ,his is a procedure used to generate user-defined errors. S'nta#( raise-application-error %errorcode, errormessage, true/false&) Error code- %range is K70000 to-70LLL&. Error message %length is 70AM b'tes&. ,rue/false- true indicates error is put in stack <alse is mentioned then the error replace all the previous errors. 8/. -'at i< a c%r< r? 2ursor is a named private SQL area from *here information can be accessed. 2ursors are re-uired to process ro*s individuall' for -ueries returning multiple ro*s. 80. -'at i< a c%r< r = r l "? 2ursor for loop implicitl' declares 13@N,OPE as loop inde#, opens a cursor, fetches ro*s of values from active set into fields in the record and closes *hen all the records have been processed. 82. F r U"(ate = Cla%<e# -*hen declaring the cursor itself *e *ill be mentioning for update clause then *e can update the records inside of the cursor. 8>. P*OCEDU*E( -$ procedure is a logicall' grouped set of SQL and PL/SQL statements that perform a specific task. /t ma' or ma' not return a value. Procedures are made up of "eclaration part E#ecutable part E#ceptional part Pere declarative part and e#ecutable part are mandator' *hile e#ceptional part is optional.

S5!ta$# -23E$,E @3 3EPL$2E P3@2E"F3E procedure name Q/+, @F,, /+@F,R Q/S, $SR 8ariable declaration) 2onstant declaration) .egin PL/SQL subprogram bod') E#ception E#ception block) End) 86. FUNCTION# - $ procedure is a logicall' grouped set of SQL and PL/SQL statements that perform a specific task. /t returns a value. <unctions having "eclaration block E#ecutable block E#ception block S5!ta$# 7 23E$,E @3 3EPL$2E <F+2,/@+ function name Q/+R 3eturn data t'pe Q/S, $SR 8ariable declaration) 2onstant declaration) .egin PL/SQL subprogram bod') E#ception E#ception block) End) 29. Di==ere!ce &et?ee! Pr ce(%re a!( F%!cti !? Procedures ma' or ma' not return a value but function should return a value Procedures *e cannot use inside of select statement <unctions are used inside of select statement 28. PA*AMETE* MODES @IN, OUT, INOUTA IN# Nhen *e pass the parameter in /+ mode that *ill *ork like a constant inside a procedure. OUT# ,his is used to return a value. INOUT# ,his *ill be using in both *a'. 22. ACTUAL PA*AMETE*S# -*hile calling the procedure *ill pass the values this *ill be calling it as actual parameters 2,. FO*MAL PA*AMETE*S#7,he procedure declaration variables *ill be receiving these values called <@3;$L parameters 2/. P*OCEDU*E O4E*LOADIN:# 7multiple procedures that are declared *ith the same name are called overloading procedures. 20. FUNCTION O4E*LOADIN:# 7 multiple functions that are declared *ith the same name are called overloading functions. 22. P*OCEDU*E, FUNCTION FO*-A*D DECLA*ATION# 7

23. PACKA:E# $ package is an oracle ob ect, *hich holds other ob ects *ith in it these ob ects ma' be Procedures <unctions 2ursors 8ariables 2onstants

, *hich are logicall' related.

2>. COMPONENTS OF PACKA:E# 7 $ package has usuall' t*o components Specification .od' $ PacBa)e S"eci=icati ! declares the t'pes, memor' variables, constants, e#ceptions, cursors and subprograms that are a variable for use. $ PacBa)e B (5 full' defines cursors, procedures and thus implements the specification. 26. PacBa)e & (5 ?it' %t <"eci=icati ! i< " <<i&le r ! t? +@. ,9. T*I::E*S# ,rigger is a PL/SQL block, *hich *ill fire automaticall' *henever an event occurs like insert, update and delete. T5"e< = tri))er<# Event I!<ert U"(ate Delete Time Be= re A=ter Level * ? leCel /t *ill fire for each ro*. StateDe!t leCel /t *ill fire onl' once for the *hole statements. ,8. T*I::E* P*EDICATES? ,hese are ! t'pes /nserting Fpdating "eleting Nhenever *e *ant to do inserting inside of the trigger that time *e *ill be using inserting predicate trigger.lll' for updating and deleting. ,2. #NE- a!( #OLD .oth *ill be used in triggers to get the ne* and old values. /n case of update both +EN and @L" are valid.

/n case of delete onl' @L" is valid. /n case of insert onl' +EN is valid. .oth( +EN and (@L" *ill *ork onl' for ro* level triggers.