the mid term exam for semester 1
TRANSCRIPT
-
8/13/2019 The Mid Term Exam for Semester 1
1/15
The Mid Term Exam for Semester 1 is presented to you as two exams. This is Part I of the MidTerm Exam for Semester 1.
Section 1
1. The P in PL/SQL stands for:
Processin
Procedura! "#$
Primary
Proprietary
%. &hich of the fo!!owin statements a'out PL/SQL and SQL is true(
PL/SQL and SQL are 'oth )*SI+comp!iant.
PL/SQL and SQL can 'e used with many types of data'ases, inc!udin -rac!e.
PL/SQL and SQL are 'oth -rac!e proprietary pro rammin !an ua es.
PL/SQL a!!ows 'asic pro ram !o ic and contro! f!ow to 'e com'ined with SQLstatements. "#$
. ) pro ram which specifies a !ist of operations to 'e performed se uentia!!y to achie0e the
desired resu!t can 'e ca!!ed:dec!arati0e
nondec!arati0e
procedura! "#$
!ow !e0e!
. 2sin -rac!e )pp!ication Express, you can create &e' app!ications that inc!ude PL/SQL.True or 3a!se(
True "#$
3a!se
-
8/13/2019 The Mid Term Exam for Semester 1
2/15
4. 5omparin PL/SQL with other !an ua es such as 5 and 6a0a, which of the fo!!owinstatements is true(
PL/SQL is harder to !earn
PL/SQL is easier to !earn and more efficient "#$
PL/SQL is easier to !earn 'ut !ess efficient
PL/SQL is easier to !earn and does not re uire an -rac!e data'ase or too!
7.&hich of the fo!!owin statements a'out exception hand!in in PL/SQL is fa!se(
8ou can prepare for data'ase exceptions 'y creatin exception hand!ers.
8ou can prepare for app!ication exceptions 'y creatin exception hand!ers.
Exception hand!in code te!!s your pro ram what to do when an error is encountered.
Exception hand!in code can 'e rouped to ether in a PL/SQL '!oc9.
*one of the a'o0e "#$
.&hat 9ind of '!oc9 is defined 'y the fo!!owin PL/SQL code(
;E-2TP2T.P2T>LI*E"?My first ui@?$A
E*=Aprocedure
su'routine
function
anonymous "#$
B.&hat is the purpose of usin =;MS>-2TP2T.P2T>LI*E in a PL/SQL '!oc9(
To perform conditiona! tests
To a!!ow a set of statements to 'e executed repeated!y
To disp!ay resu!ts to chec9 if our code is wor9in correct!y "#$
To store new rows in the data'ase
-
8/13/2019 The Mid Term Exam for Semester 1
3/15
C.
-
8/13/2019 The Mid Term Exam for Semester 1
4/15
1%. In which part of the PL/SQL '!oc9 are dec!arations of 0aria'!es defined(
Executa'!e
Exception
=ec!arati0e "#$
=efinition
1 . Errors are hand!ed in the Exception part of the PL/SQL '!oc9. True or 3a!se(
True "#$
3a!se
1 . E0a!uate the fo!!owin dec!aration. =etermine whether or not it is !e a!.
=E5L) E
maxsa!ary *2M;E " $ H 4FFFA
5orrect.
*ot correct. "#$
14. aria'!es can 'e used in the fo!!owin ways in a PL/SQL '!oc9. "5hoose two.$
"5hoose a!! correct answers$
To store data 0a!ues. "#$
To rename ta'!es and co!umns.
To refer to a sin !e data 0a!ue se0era! times. "#$
To comment code.
17. &hen a 0aria'!e is defined usin the *-T *2LL 9eywords, the 0aria'!e must contain a0a!ue. True or 3a!se(
True "#$
3a!se
-
8/13/2019 The Mid Term Exam for Semester 1
5/15
1 . Identify which of the fo!!owin assi nment statements are 0a!id. "5hoose three.$
"5hoose a!! correct answers$
0>!ast>name :H 5handraA
0>'!ac9out>date :H ? 1+=E5+%FF7?A "#$
0>popu!ation :H A "#$
0>music>type :H ? -5J?A "#$
1B. Is the fo!!owin 0aria'!e dec!aration correct or not (
=E5L) E
disp!ay> ty 5-*ST)*T *2M;E A
5orrect.
*ot correct. "#$
1C. &hich of the fo!!owin are disad0anta es of imp!icit data type con0ersions( "5hoose two.$
"5hoose a!! correct answers$
The code is harder to read and understand "#$
8ou cannot store a!pha'etic characters in a 0aria'!e of data type *2M;E
If -rac!e chan es the con0ersion ru!es in the future, your code may not wor9 any more "#$
-rac!e cannot imp!icit!y con0ert a num'er 0a!ue to a character strin
%F. Examine the fo!!owin code:
1 =E5L) E
% x *2M;E A
;E
-
8/13/2019 The Mid Term Exam for Semester 1
6/15
%1. If today?s date is 1 th 6une %FF , which statement wi!! correct!y con0ert today?s date to the0a!ue: 6une 1 , %FF (
T->5K) "sysdate$
T->=)TE"sysdate$
T->=)TE"sysdate,?Month ==, 8888?$
T->5K) "sysdate, ?Month ==, 8888?$ "#$
%%.The =E5-=E function is a0ai!a'!e in PL/SQL procedura! statements. True or 3a!se(
True
3a!se "#$
%
% .&hen you use a function to con0ert data types in a PL/SQL pro ram, it is ca!!ed >>>>>>con0ersion.
Exp!icit "#$
Imp!icit
T->5K)
% . &hat is the output when the fo!!owin pro ram is executed(
=E5L) E
a ) 5K) %"1F$ :H ? ?A
' ) 5K) %"1F$ :H ? ?A
c PLS>I*TE*2M;E "'$A
d :H a 'A
=;MS>-2TP2T.P2T>LI*E"c$A
=;MS>-2TP2T.P2T>LI*E"d$A
E*=A
-
8/13/2019 The Mid Term Exam for Semester 1
7/15
*othin . The code wi!! resu!t in an error.
cH and dH "#$
cH and dH
cH and dH
%4. T->*2M;E , T->5K) , and T->=)TE are a!! examp!es of:
Imp!icit con0ersion functions
Exp!icit con0ersion functions "#$
5haracter functions
-perators
%7. Examine the fo!!owin code. &hat is the fina! 0a!ue of >M8 ) (
=E5L) E
0>my0ar *2M;E A
;Emy0ar :H 1 % # A
0>my0ar :H 0>my0ar # %A
E*=A
B1 C 1 "#$ 1B
% . 1. *u!!
%. 3a!se
. True
. F
&hich of the a'o0e can 'e assi ned to a ;oo!ean 0aria'!e(
% and
%, and
1, % and "#$
1, %, and
-
8/13/2019 The Mid Term Exam for Semester 1
8/15
%B. 8ou need to dec!are a 0aria'!e to ho!d a 0a!ue which has 'een read from the S)L) 8co!umn of the EMPL-8EES ta'!e. &hich of the fo!!owin is an ad0anta e of dec!arin the0aria'!e as: emp!oyees.sa!aryNT8PE (
It is shorter than codin *2M;E "B,%$
If the S)L) 8 co!umn is )LTE ed !ater, the PL/SQL code need not 'e chan ed. "#$It executes much faster than usin *2M;E "B,%$
It a!!ows the software to perform imp!icit data type con0ersions.
%C. If you are usin the NT8PE attri'ute, you can a0oid hard codin the
=ata type "#$
Ta'!e name
5o!umn name
5onstraint
F. &hat is the data type of the 0aria'!e >=EPT>T);LE in the fo!!owin dec!aration(
=E5L) E
T8PE dept>ta'!e>type IS T);LE -3 departmentsN -&T8PE I*=ED ;8 PLS>I*TEdept>ta'!e dept>ta'!e>typeA ...
Sca!ar 5omposite "#$
L-;
1. ) mo0ie is an examp!e of which cate ory of data type(
Sca!ar
5omposite
eference
L-; "#$
-
8/13/2019 The Mid Term Exam for Semester 1
9/15
%. ) co!!ection is a composite data type. True or 3a!se(
True "#$
3a!se
. =e!imiters are >>>>> that ha0e specia! meanin to the -rac!e data'ase.
identifiers
0aria'!es
sym'o!s "#$
. &hich statements a'out !exica! units are true( "5hoose two.$
"5hoose a!! correct answers$
They are named o'Gects stored in the data'ase
They are the 'ui!din '!oc9s of e0ery PL/SQL pro ram "#$
They are optiona! 'ut can ma9e a PL/SQL '!oc9 execute faster
They are se uences of characters inc!udin !etters, di its, ta's, returns and sym'o!s "#$
4. eser0ed words can 'e used as identifiers. True or 3a!se(
True
3a!se "#$
7. &hen an exception occurs within a PL/SQL '!oc9, the remainin statements in theexecuta'!e section of the '!oc9 are s9ipped. True or 3a!se(
True "#$
3a!se
. when nested '!oc9s are used, which '!oc9s can or must 'e !a'e!ed(
The inner '!oc9 must 'e !a'e!ed, the outer '!oc9 can 'e !a'e!ed.
;oth '!oc9s must 'e !a'e!ed
*ested '!oc9s cannot 'e !a'e!ed
The outer '!oc9 must 'e !a'e!ed if it is to 'e referred to in the inner '!oc9. "#$
-
8/13/2019 The Mid Term Exam for Semester 1
10/15
-
8/13/2019 The Mid Term Exam for Semester 1
11/15
F. &hat wi!! 'e disp!ayed when the fo!!owin code is executed(
=E5L) E
0ar) *2M;E :H 1%A
;ELI*E"0ar;$A
E*=A
B 1% *othin , the '!oc9 wi!! fai! with an error "#$ %F ar;
1. ) PL/SQL '!oc9 inc!udes the fo!!owin statement:
SELE5T !ast>name I*T- 0>!ast>name
3 -M emp!oyees
&KE E emp!oyee>idH1FFA
&hat is the 0a!ue of SQLNIS-PE* immediate!y after the SELE5T statement is executed(
True
3a!se "#$
*u!!
Error. That attri'ute does not app!y for imp!icit cursors.
%. There are no emp!oyees in =epartment . &hat wi!! happen when the fo!!owin '!oc9 isexecuted(
;EidH A
-
8/13/2019 The Mid Term Exam for Semester 1
12/15
=;MS>-2TP2T.P2T>LI*E"SQLN -&5-2*T$
E*=A
) *->=)T)>3-2*= exception is raised.
) *2LL is disp!ayed.
) @ero "F$ is disp!ayed. "#$
)n exception is raised 'ecause the '!oc9 does not contain a 5-MMIT statement.
. &hich is the correct way to erase one row from a ta'!e(
EM- E emp!oyee>idH1FF
3 -M emp!oyeesA
= -P T);LE emp!oyees
&KE E emp!oyee>idH1FFA
T 2*5)TE emp!oyees
&KE E emp!oyee>idH1FFA
=ELETE 3 -M emp!oyees
&KE E emp!oyee>idH1FFA "#$
. &hich one of these SQL statements can 'e direct!y inc!uded in a PL/SQL executa'!e'!oc9(
=ELETE 3 -M emp!oyees
&KE E department>idH7FA "#$
SELE5T sa!ary 3 -M emp!oyees
&KE E department>idH7FA
5 E)TE T);LE new>emps "!ast>name ) 5K) %"1F$, first>name ) 5K) %"1F$$A
= -P T);LE !ocationsA
-
8/13/2019 The Mid Term Exam for Semester 1
13/15
4. &hich rows wi!! 'e de!eted from the EMPL-8EES ta'!e when the fo!!owin code isexecuted(
=E5L) E
sa!ary emp!oyees.sa!aryNT8PE :H 1%FFFA
;Ename 3 -M emp!oyees
&KErE emp!oyee>idH1FFA
=ES5 I;E emp!oyeesA
2P=)TE emp!oyees
SET !ast>nameH?Smith?A "#$
= -P T);LE emp!oyeesA
. ) 0aria'!e is dec!ared as:
=E5L) E
0>ho!dit emp!oyees.!ast>nameNT8PEA;Eho!dit 3 -M emp!oyeesA
SELE5T !ast>name I*T- 0>ho!dit 3 -M emp!oyeesA
-
8/13/2019 The Mid Term Exam for Semester 1
14/15
SELE5T !ast>name I*T- 0>ho!dit 3 -M emp!oyees &KE E emp!oyee>idH1FFA "#$
SELE5T sa!ary I*T- 0>ho!dit 3 -M emp!oyees &KE E emp!oyee>idH1FFA
B. ) 0aria'!e is dec!ared as:
=E5L) E
0>sa!ary emp!oyees.sa!aryNT8PEA
;Esa!ary 3 -M emp!oyees &KE E emp!oyee>idH1FFA "#$
SELE5T 0>sa!ary I*T- sa!ary 3 -M emp!oyees &KE E emp!oyee>idH1FFA
SELE5T sa!ary 3 -M emp!oyees I*T- 0>sa!aryA
SELE5T sa!ary 3 -M emp!oyees &KE E emp!oyee>idH1FF I*T- 0>sa!aryA
C. Kow many =ML statements can 'e inc!uded in a sin !e transaction(
-n!y one
*one. ) transaction cannot inc!ude =ML statements.
) maximum of four =ML statements
)s many as needed "#$
-
8/13/2019 The Mid Term Exam for Semester 1
15/15
4F. The fo!!owin anonymous '!oc9 of code is run:
;E