Basic InterviewQuestions For

5

Click here to load reader

Transcript of Basic InterviewQuestions For

Page 1: Basic InterviewQuestions For

8/10/2019 Basic InterviewQuestions For

http://slidepdf.com/reader/full/basic-interviewquestions-for 1/5

Basic InterviewQuestions for PL/SQL

September 13, 2007

ripalmsoni SQL SERVER-PL/SQL - ORACLE 10 Comments

1. What is PL/SQL ?Ans. PL/SQL is a procedural language that has both interactive SQL and proceduralprogramming language constructs such as iteration, conditional branching.

2. What is the basic structure of PL/SQL ?Ans. PL/SQL uses block structure as its basic structure. Anonymous blocks or nested blocks canbe used in PL/SQL.

3. What are the components of a PL/SQL block ?

Ans. A set of related declarations and procedural statements is called block.

4. What are the components of a PL/SQL lock ?Ans. Declarative part, !ecutable part and !ception part.Datatypes PL/SQL

!. What are the "atat#pes a a$ailable in PL/SQL ?Ans. Some scalar data types such as "#$% &, 'A&()A&*, DA+ , ()A&, L "-, % L A".Some composite data types such as & ( &D +A%L .

%. What are & '(P) an" & *+W'(P) ? What are the a"$anta,es of usin, these o$er"atat#pes?Ans. +0P provides the data type of a variable or a database column to that variable.

& 1+0P provides the record type that represents a entire ro2 of a table or vie2 or columnsselected in the cursor.+he advantages are 3 4. "eed not kno2 about variable5s data typeii. 4f the database definition of a column in a table changes, the data type of a variable changesaccordingly.

-. What is "ifference bet een & *+W'(P) an" '(P) *) +*0 ?Ans. & 1+0P is to be used 2henever 6uery returns a entire ro2 of a table or vie2.+0P rec & ( &D is to be used 2henever 6uery returns columns of different

table or vie2s and variables..g. +0P r7emp is & ( &D 8eno emp.empno type,ename emp ename type

9:e7rec emp & 1+0Pcursor c; is select empno,deptno from emp:e7rec c; & 1+0P .

. What is PL/SQL table ?Ans. b<ects of type +A%L are called =PL/SQL tables>, 2hich are modeled as 8but not the sameas9 database tables, PL/SQL tables use a primary PL/SQL tables can have one column and a

Page 2: Basic InterviewQuestions For

8/10/2019 Basic InterviewQuestions For

http://slidepdf.com/reader/full/basic-interviewquestions-for 2/5

primary key.. What is a cursor ? Wh# ursor is re uire" ?

Ans. (ursor is a named private SQL area from 2here information can be accessed. (ursors arere6uired to process ro2s individually for 6ueries returning multiple ro2s.

1 . )5plain the t o t#pe of ursors ?+here are t2o types of cursors, 4mplicit (ursor and !plicit (ursor.PL/SQL uses 4mplicit (ursors for 6ueries.#ser defined cursors are called !plicit (ursors. +hey can be declared and used.11. What are the PL/SQL Statements use" in cursor processin, ?Ans. D (LA& (#&S & cursor name, P " cursor name, ? +() cursor name 4"+ or&ecord types, (L S cursor name.12. What are the cursor attributes use" in PL/SQL ?Ans. 4S P " @ to check 2hether cursor is open or not

& 1( #"+ @ number of ro2s fetched/updated/deleted. ? #"D @ to check 2hether cursor has fetched any ro2. +rue if ro2s are fetched. " + ? #"D @ to check 2hether cursor has fetched any ro2. +rue if no ro2s are fetched.

+hese attributes are proceeded 2ith SQL for 4mplicit (ursors and 2ith (ursor name for !plicit(ursors.13. What is a cursor for loop ?Ans. (ursor for loop implicitly declares & 1+0P as loop inde!, opens a cursor, fetches ro2sof values from active set into fields in the record and closes2hen all the records have been processed.eg. ? & emp7rec 4" (; L Psalary7total 3 salary7total Bemp7rec sal:

"D L P:14. What ill happen after commit statement ?Ans. (ursor (; isSelect empno,ename from emp:%eginopen (;: loop?etch (; into

eno.ename:!it 1hen

(; notfound:C@commit:end loop:end: +he cursor having 6uery as S L (+ . ? & #PDA+ gets closed after( $$4+/& LL%A(E.+he cursor having 6uery as S L (+ . does not get closed even after ( $$4+/& LL%A(E.1!. )5plain the usa,e of W6)*) 7**)8' +9 clause in cursors ?Ans. 1) & (#&& "+ ? clause in an #PDA+ , D L + statement refers to the latest ro2fetched from a cursor.1%. What is a "atabase tri,,er ? 8ame some usa,es of "atabase tri,,er ?Ans. Database trigger is stored PL/SQL program unit associated 2ith a specific database table.

#sages are Audit data modifications, Log events transparently, nforce comple! business rulesDerive column values automatically, 4mplement comple! security authoriFations. $aintainreplicate tables.1-. 6o man# t#pes of "atabase tri,,ers can be specifie" on a table ? What are the# ?Ans. 4nsert #pdate Delete%efore &o2 o.k. o.k. o.k.

After &o2 o.k. o.k. o.k.%efore Statement o.k. o.k. o.k.

After Statement o.k. o.k. o.k.4f ? & A() & 1 clause is specified, then the trigger for each &o2 affected by the statement.

Page 3: Basic InterviewQuestions For

8/10/2019 Basic InterviewQuestions For

http://slidepdf.com/reader/full/basic-interviewquestions-for 3/5

4f 1) " clause is specified, the trigger fires according to the returned boolean value.

1 . :s it possible to use 'ransaction control Statements such a *+LL A ; or +<<:' in0atabase 'ri,,er ? Wh# ?Ans. 4t is not possible. As triggers are defined for each table, if you use ( $$4+ of & LL%A(E ina trigger, it affects logical transaction processing.

1 . What are t o $irtual tables a$ailable "urin, "atabase tri,,er e5ecution ?Ans. +he table columns are referred as LD.column7name and " 1.column7name.?or triggers related to 4"S &+ only " 1.column7name values only available.?or triggers related to #PDA+ only LD.column7name " 1.column7name values onlyavailable.?or triggers related to D L + only LD.column7name values only available.

2 . What happens if a proce"ure that up"ates a column of table = is calle" in a "atabasetri,,er of the same table ?Ans. $utation of table occurs.

21. What is an )5ception ? What are t#pes of )5ception ?Ans. !ception is the error handling part of PL/SQL block. +he types are Predefined anduser7defined. Some of Predefined e!ceptions are.(#&S &7AL& AD07 P "D#P7'AL7 "74"D G" 7DA+A7? #"D+ 7$A"07& 1S4"'AL4D7(#&S &4"'AL4D7"#$% &L - "7D "4 D" +7L -- D7 "P& -&A$H && &S+ &A- 7 && &+4$ #+7 "7& S #&('AL# 7 && &

I & 7D4'4D+) &S.

22. What is Pra,ma )=) P':+8>:8:' ? )5plain the usa,e ?Ans. +he P&A-$A G (P+4 "74"4+ tells the complier to associate an e!ception 2ith an oracleerror. +o get an error message of a specific oracle error.e.g. P&A-$A G( P+4 "74"4+ 8e!ception name, oracle error number9

23. What is *aise>application>error ?Ans. &aise7application7error is a procedure of package D%$S7S+A"DA&D 2hich allo2s toissue an user7defined error messages from stored subHprogram or database trigger.

24. What are the return $alues of functions SQL +0) an" SQL)**< ?

Ans. SQL( D returns the latest code of the error that has occurred.SQL &&$ returns the relevant error message of the SQL( D .2!. Where the Pre>"efine">e5ceptions are store" ?Ans. 4n the standard package.2%. What is a store" proce"ure ?Ans. A stored procedure is a se6uence of statements that perform specific function.

2-. What is "ifference bet een a P*+ )07*) 978 ':+8 ?Ans. A ?#"(+4 " al2ays returns a value using the return statement.

A P& ( D#& may return one or more values through parameters or may not return at all.

Page 4: Basic InterviewQuestions For

8/10/2019 Basic InterviewQuestions For

http://slidepdf.com/reader/full/basic-interviewquestions-for 4/5

2 . What are a"$anta,es fo Store" Proce"ures ?Ans. !tensibility, $odularity, &eusability, $aintainability and one time compilation.

2 . What are the mo"es of parameters that can be passe" to a proce"ure ?Ans. 4", #+, 4"H #+ parameters.

3 . What are the t o parts of a proce"ure ?Ans. Procedure Specification and Procedure %ody.

31. @i$e the structure of the proce"ure ?Ans. P& ( D#& name 8parameter list ..9islocal variable declarations% -4"

!ecutable statements.!ception.

e!ception handlersend:

32. @i$e the structure of the function ?Ans. ?#"(+4 " name 8argument list ..9 &eturn datatype islocal variable declarations%egine!ecutable statements

!ceptione!ecution handlers

nd:

33. )5plain ho proce"ures an" functions are calle" in a PL/SQL block ?Ans. ?unction is called as part of an e!pression.sal 3 calculate7sal 8JaK** 9:procedure is called as a PL/SQL statement

calculate7bonus 8JAK** 9:

34. What is +$erloa"in, of proce"ures ?Ans. +he Same procedure name is repeated 2ith parameters of different datatypes andparameters in different positions, varying number of parameters is called overloading ofprocedures.e.g. D%$S7 #+P#+ put7line

3!. What is a packa,e ? What are the a"$anta,es of packa,es ?Ans. Package is a database ob<ect that groups logically related procedures.+he advantages of packages are $odularity, asier Application Design, 4nformation. )iding,.reusability and %etter Performance.

3%.What are t o parts of packa,e ?Ans. +he t2o parts of package are PA(EA- SP (4?4(A+4 " PA(EA- % D0.Package Specification contains declarations that are global to the packages and local to theschema.Package %ody contains actual procedures and local declaration of the procedures and cursordeclarations.

3-. What is "ifference bet een a ursor "eclare" in a proce"ure an" ursor "eclare" in apacka,e specification ?

Page 5: Basic InterviewQuestions For

8/10/2019 Basic InterviewQuestions For

http://slidepdf.com/reader/full/basic-interviewquestions-for 5/5

Ans. A cursor declared in a package specification is global and can be accessed by otherprocedures or procedures in a package.

A cursor declared in a procedure is local to the procedure that can not be accessed by otherprocedures.

3 . 8ame the tables here characteristics of Packa,e proce"ure an" functions are

store" ?Ans. #ser7ob<ects, #ser7Source and #ser7error