Vous êtes sur la page 1sur 22

RESTRICTINGANDSORTINGDATAQUESTIONS

http://www.tutorialspoint.com/sql_certificate/restricting_and_sorting_data_questions.htm
Copyrighttutorialspoint.com

1.Whichofthefollowingclauseisusedtolimitthenumberofrowsretrievedfroma
SELECTquery?
A. LIMIT
B. WHERE
C. AND
D. FROM
Answer:B.TheWHEREclauseisusedtorestrictthenumberofrowsreturnedfromaSELECTquery.
2.ChoosethedatabaseelementswhosevaluescanbecomparedinaWHEREclauseofa
SELECTquery.
A. Column
B. Sequence
C. Procedure
D. Literal
Answer:A,D.TheWHEREclausecanbeusedtocomparethevaluesfromcolumns,literals,
arithmeticfunctionsandfunctions.
3.WhataretheelementsNOTcontainedintheWHEREclausepredicateoftheSELECT
query?
A. Comparisonoperator
B. Comparisoncondition
C. ColumnName
D. TableName
Answer:D.TableNameisnotrequiredintheWHEREclausepredicate.
4.WhichofthefollowingvaluescanNOTbereturnedafterevaluationofWHERE
clausecondition?
A. UNKNOWN
B. TRUE
C. FALSE
D. NULL
Answer:A.IftheresultoftheconditioninWHEREclauseisnotknown,NULLisreturned.Inall
otherscenarios,eitherTRUEorFALSEisreturned.

5.WhatistheminimumnumberofWHEREclausesthatmustbepresentinaSELECT
query?
A. 1
B. 2
C. 0
D. 3
Answer:C.TheWHEREclauseisanoptionalclauseintheSELECTquerywhichisonlyusedto
restrictthenumberofrows.
6.WhatisthemaximumnumberofWHEREclausesthatcanbeincludedinaSELECT
query?
A. 1
B. 2
C. 0
D. 3
Answer:A.TheWHEREclauseisanoptionalclauseintheSELECTquerywhichcanbeusedonly
oncetorestrictthenumberofrows.
7.WhichofthefollowingstatementsarecorrectabouttheWHEREclause?
A. ColumnAliascanbeusedinWHEREclausetoreferacolumn
B. ComparisonoperatorisanoptionalelementinWHEREclausecondition
C. FunctionscanbeusedasoperandsintheWHEREclause
D. TherecanbemultipleWHEREclauseinaSELECTquery
Answer:C.TheWHEREclausemusthavecomparisonoperatortoevaluatethecondition.Itcanuse
functionasoneoftheoperand.OnlyoneWHEREclauseisallowedinaSELECTquery.
8.WriteaSELECTquerytolistdownuniquedepartmentsfromEMPtable?
. SELECTdeptnoFROMemp;
. SELECTDISTINCTdeptnoFROMemp;
. SELECTDISTINCT(deptno)FROMemp;
. SELECTempno,DISTINCTdeptnoFROMemp;
Answer:B.ThekeywordDISTINCTisusedtofilterouttheduplicaterowsfromtheSELECTquery.
9.Whichofthefollowingoperationsisnotpermittedfordateandtimestampcolumns?
A. Division

B. Addition
C. Subtraction
D. Concatenation
Answer:A,D.Additionandsubtractionarethetwooperationspermittedfordateandtimestamp
columns.
10.Fromthebelowoperators,whichoneofthemholdsthehighestprecedencelevel?
A. Division/
B. Multiplication
C. Brackets()
D. Subtraction
Answer:C.Expressionswithinthebracketsholdthehighestprecedencelevel.
11.InterprettheoutputreturnedbythebelowSELECTquery
SELECTename,(sysdatehiredate)
FROMemp;

A. Numberofdaysinthecurrentyear
B. Numberofdaysintheyearwhenanemployeewashired
C. Numberofdaysspentbyemployeewiththecompany
D. Thequeryraisesexception"ORA00932:inconsistentdatatypes:expectedNUMBERgotDATE"
Answer:C.Theexpressionsysdate hiredate returnsthenumberofemploymentdaysofan
employeewiththecompany.
12.WhichofthebelowstatementscorrectlydescribletheDUALtableinOracle?
A. DUALtableisatemporarytableinOracledatabase
B. DUALtablecontainsonlyonecharactertypecolumnknownasDUMMY
C. DUALtableownedbySYScannotbedropped
D. AtablewiththenameDUALcanbecreatedbyauserinitsownschema
Answer:B,C,D.TheDUALtableinOracleisownedbySYSandcontainsonecolumnDUMMYof
typeVARCHAR21 .
13.Determinethetypeofoutputreturnedbythebelowquery
SELECTsysdatehiredate
FROMemp
WHEREempno=7369;

A. DATEdatatype

B. NUMBERdatatype
C. VARCHAR2datatype
D. Thequeryraiseserrorsincearithmeticoperationscannotbeperformedondatecolumns
Answer:B.Subtractionbetweentwodatesresultsinnumericdifferenceofdaysbetweenthetwo
dates
14.WhichexpressionsdoNOTreturnNULLvalues?
. SELECT((10+20)*50)+nullfromdual;
. SELECT'thisisa'||null||'testwithnulls'fromdual;
. SELECTnull/0fromdual;
. SELECTnull||'test'||nullasTestfromdual;
Answer:B,D.AnyarithmeticoperationwithNULLresultsinNULL.
15.Determinetheoutputofthebelowquery
SELECT'Tutorial''sPointcompilestechnicaltutorials'FROMDUAL;

A. Tutorial''sPointcompilestechnicaltutorials
B. Tutorial'sPointcompilestechnicaltutorials
C. 'Tutorial''sPointcompilestechnicaltutorials'
D. Raisesexception"ORA01756:quotedstringnotproperlyterminated"
Answer:B.
16.ExaminetheTRAININGtableasgivenbelow:
NameNull?Type

TRAINING_IDNOTNULLNUMBER(5)
TRAINING_LOCATIONNUMBER(7,2)
START_DATEDATE
END_DATEDATE

WhichtwoSQLwouldexecutesuccessfully?C hoosetwo
. SELECTNVL(ADD_MONTHS(END_DATE,1),SYSDATE)FROMtraining;
. SELECTTO_DATE(NVL(SYSDATEEND_DATE,SYSDATE))FROMtraining;
. SELECTNVL(MONTHS_BETWEEN(START_DATE,END_DATE),InProgress)FROMtraining;

. SELECTNVL(TO_CHAR(MONTHS_BETWEEN(START_DATE,END_DATE)),InProgress)FROM
training;

Answer:A,D.UseNVLfunctiontoprovideanalternatevaluetoacolumnwhenNULL.
17.WhatdoestheselectionofcolumnsinaSELECTstatementknownas?
A. Retrieval
B. Selection
C. Projection
D. Limiting
Answer:C.ProjectionistheabilitytoselectonlytherequiredcolumnsinSELECTstatement.
18.WhatdoestherestrictionofrowsreturnedbyaSELECTstatementknownas
A. Retrieval
B. Projection
C. Restricting
D. Selection
Answer:C.Restrictingistheabilitytolimitthenumberofrowsbyputtingcertainconditions.
19.Whichofthefollowingistrueaboutthequerygivenbelow?
SELECTcol1,col2
FROMtab1
ORDERBYcol1;

A. AlltherowsforthecolumnCOL1willbesortedintheDescendingorder.
B. AlltherowsforthecolumnCOL1willbesortedintheAscendingorder.
C. ThequerywillgiveanerrorasthereisnoWHEREclauseinthequery.
D. ThequerywillgiveanerrorastheORDERBYclauseshouldincludeallthecolumnsinthe
SELECTclause.
Answer:B.Bydefault,theORDERBYclausesortsthevaluesinascendingorder.
20.WhichofthefollowingistrueabouttheSQLquerygivenbelow?
SELECTcol1,col2
FROMtab1
WHEREcol1='A'
ORDERBYcol2DESC,col1;

A. Itwilldisplaytherowwhichhasthecol1valueas'A'orderedbythecol1inthedescendingorder
andthencol2inthedescendingorder.
B. TheORDERBYclausewillnotworkasthekeywordDESCshouldbealwayswrittenintheendof

theORDERBYclauseandnotinbetweenasgiveninthequery.
C. Theabovequerywillbesortedindescendingorderonthebasisofcol2onlyandtheuseofcol1in
theORDERBYclausewillbediscarded.
D. Itwilldisplaytherowwhichhasthecol1valueas'A'orderedbythecol1andthenfollowedbycol2
astheexecutionoftheORDERBYclausehappensfromtheorderofcolumnsintheSELECT
statement.
Answer:C.SincetheCOL1isalreadyfilteredandfixedinthequeryasascalarvalue,nosortingwill
happenonthebasisofCOL1.
21.Whatistrueregardingthequerygivenbelow?
SELECTcol1,col2
FROMtab1
ORDERBYcol1,col2
WHEREcol2='B';

A. Itexecutessuccessfully
B. ItgivestherequiredresultwiththeCOL2valueas'B'butnoorderingbythecolumnsCOL1and
COL2becauseORDERBYclauseappearsbeforetheWHEREclause.
C. ItwilldisplaytherowwhichhastheCOL2valueas'B'orderedbytheCOL1,COL2.
D. ItthrowsanerrorastheORDERBYclausecannotbewrittenbeforetheWHEREclausein
Oracle.
Answer:D.TheORDERBYclausemustappearaftertheWHEREclauseintheSELECTstatement
22.WhichtwoclausesoftheSELECTstatementarenecessaryforSelectionand
Projection?
A. SELECT,FROM
B. ORDERBY,WHERE
C. SELECT,WHERE
D. SELECT,ORDERBY
Answer:C.
23.WhichofthefollowingWHEREclauseswillNOTfitinthebelowSELECTquery?
SELECTename,deptno,sal
FROMemp;

A. WHEREHIREDATEIN 02 J U N 2004

B. WHERESALIN 1000 ,

4000 , 2000

C. WHEREJOBINS ALES , C LERK


D. WHERECOMMBETWEEN0.1AND0.5
Answer:C.Characterliteralsmustbeenclosedwithinsinglequotes

24.ChoosetheWHEREclausethatextractstheDNAMEvaluescontainingthecharacter
literalerfromtheDEPTtable.
A. WHEREDNAMEIN

B. WHEREDNAMELIKE'%er%'
C. WHEREDNAMEBETWEEN'e'AND'r'
D. WHEREDNAMECONTAINS'e%r'
Answer:B.TheLIKEoperatorisusedtoperformwildcardsearchinSQLqueries.
25.Whichtwoofthefollowingconditionsareequivalenttoeachother?
A. WHEREcommISNULL
B. WHEREcomm=NULL
C. WHEREcommINN U LL
D. WHERENOTcommI S N OT N U LL
Answer:A,D.TheNOToperatorcanbeusedtonegatetheeffectofitsoperand.Therefore
C OM M I S N U LLisequivalenttoN OT (C OM M I S N OT N U LL ).
26.WhichofthefollowingclausesaremandatoryinanSQLquery?
A. SELECT,FROM
B. SELECT,FROM,WHERE
C. SELECT,WHERE
D. SELECT,WHERE,ORDERBY
Answer:A.SELECTandFROMarethemandatoryclausesinaSELECTquery.
27.WhichthreeofthefollowingWHEREclauseconditionsareequivalenttoeach
other?
A. WHERESAL<=5000ANDSAL>=2000
B. WHERESALIN2000, 3000, 4000, 5000
C. WHERESALBETWEEN2000AND5000
D. WHERESAL>1999ANDSAL<5001
Answer:A,C,D.TheconditionscanbemadeequivalentwiththeuseofIN,BETWEENand
relationaloperators
28.Whichofthefollowingistruewithrespecttothebelowquery?
SELECTempno,ename,job
FROMemp
WHEREenamelike'_ith%';

A. Itfetchestheemployeeid,nameandjobofthoseemployeeswhohave'ith'appearinganywhere

intheirname.
B. Itfetchestheemployeeid,nameandjobofthoseemployeeswhosenamestartswith'ith'.
C. Thequerythrowsanerrorastwoexpressionsforstringmatchingcannotbewrittentogether.
D. Itfetchestheemployeeid,nameandjobofthoseemployeeswhosenamestartswithany
alphanumericcharacterfollowedby'ith'andanyalphanumericcharactersafter'ith'.
Answer:D.
29.WhichofthefollowingisusedtoendaSQLquery?
A. :
B.
C. .
D. /
Answer:B,D.Asemicolon;orbackslash/ isusedtoterminateaqueryinSQL*PlusandSQL
Developer.
30.TheemployeesJAMESandMILLERwanttoknowtheirdepartmentidbyquerying
thedatabase.Whichofthefollowingquerieswillgivetherequiredresult?
. SELECTename,deptnoFROMempWHEREename='JAMES';
. SELECTename,deptnoFROMempWHEREename='MILLER';
. SELECTename,deptnoFROMdept
. SELECTename,deptnoFROMempWHEREename='JAMES'ORename='MILLER'
Answer:D.MultipleconditionscanbejoinedusingORclause.Queryexecutionissuccessfulifeither
ofthetwoistrue.
31.WhichofthefollowingisfalseregardingtheWHEREclause?
A. TheWHEREcancomparevaluesincolumns,literal,arithmeticexpressions,orfunctions.
B. TheWHEREclausecontainscolumnname
C. ColumnaliasescanbeusedintheWHEREclause.
D. TheWHEREclausecannotcontainlistofvaluesorconstants.
Answer:C,D.
32.WhatisthedefaultdateformatinOracle?
A. DDMONYY
B. DDMONYYYY
C. DDMMRR

D. DDMONRR
Answer:D.DDMONRRisthedefaultdateformatinOracle.
33.PredicttheoutputofthebelowSQLquery.
SELECTename,deptno,sal,comm
FROMemp
WHEREjob='SALES'
ANDhiredate=01JAN97;

A. ItfetchestheemployeedataforallSALESemployees
B. Itthrowsanerror"ORA00904:"01JAN13":invalididentifier"
C. Queryexecutessuccessfullybutnoresultsarereturned
D. ItfetchesthedataforallSALESemployeeswhowerehiredon01stJan,1997
Answer:B.Dateliteralsmustbeenclosedwithinsinglequotes.
34.Youneedtodisplaythenamesofalltheemployeeshavingthefirstnameas
"GARRY"fromtheEMPLOYEEStable.Whichofthefollowingquerieswillfulfillthe
requirement?
. SELECTfirst_nameFROMemployeesWHEREfirst_nameLIKE'GARRY%';
. SELECTfirst_nameFROMemployeesWHEREfirst_nameLIKE'%GARRY%';
. SELECTfirst_nameFROMemployeesWHEREfirst_nameLIKE'GARRY';
. SELECTfirst_nameFROMemployeesWHEREfirst_nameLIKE'_ARRY%';
Answer:C.WildCardscanbeusedifcertaincharactersofthesearchstringareunknown.
35.YouneedtodisplaytheemployeeIDofalltheemployeeswhocontainaletter's'in
theirlastnameatsecondpositionanddepartmentIDas100.Whichofthefollowing
querieswillfetchtherequiredresults?
. SELECTemp_idFROMemployeesWHEREdept_id=100ANDlast_nameLIKE'%s%';
. SELECTemp_idFROMemployeesWHEREdept_id=100ANDlast_nameLIKE'%s_';
. SELECTemp_idFROMemployeesWHEREdept_id=100ANDlast_nameLIKE'_s_%';
. SELECTemp_idFROMemployeesWHEREdept_id=100ANDlast_nameLIKE'_s%';
Answer:D.Thewildcardcharacterunderscore _ isusedtosubstituteasinglecharacter.
36.Whatwillbetheoutcomeofthebelowquery?
SELECTfirst_name,last_name,dept_id

FROMemployees
WHEREhire_dateLIKE'%98';

A. Thefirstname,lastnameandthedepartmentIDforalltheemployeeswhojoinedintheyear
1998willbedisplayed.
B. Thefirstname,lastnameandthedepartmentIDforalltheemployeeswhojoinedintheyear
2098willbedisplayed.
C. Noresultswillbereturned.
D. Thefirstname,lastnameandthedepartmentIDforalltheemployeeswhojoinedintheyear
1998between1stJanuary,1998and31stDecember,1998willbedisplayed.
Answer:D.TheLIKEoperatorisusedtoperformwildcardsearchoncharacteranddateliterals.
37.Whichofthefollowingisusedtogetrowsbasedonarangeofvalues?
A. UNIONALL
B. IN
C. BETWEEN
D. LIKE
Answer:C.TheBETWEENoperatorisusedtoretrieverowsbasedonrangeofvalues.
38.YouneedtodisplaytheemployeeIDsoftheemployeeswhohavetheirsalaries
between20000 inclusive and50000inclusive .Whichofthefollowingquerieswillfetch
therequiredresults?
. SELECTemp_idFROMemployeesWHEREsalary>=20000ANDsalary<=50000;
. SELECTemp_idFROMemployeesWHEREsalaryIN(20000,50000);
. SELECTemp_idFROMemployeesWHEREsalary>20000ANDsalary<50000;
. SELECTemp_idFROMemployeesWHEREsalarybetween20000AND50000;
Answer:A,D.Forlargerrangesofvalues,BETWEENandrelationaloperatorsarebestsuitedinthe
queries.INoperatorisnotrecommendedforlargerangeofvalues.
39.Whatistruewithrespecttothebelowquery?
SELECTfirst_name,last_name
FROMemployees
WHERElast_nameBETWEEN'B%'AND'E%';

A. Itwilldisplayalltheemployeeshavinglastnamesstartingwiththealphabets'B'till'E'inclusive
ofboththecharacters.
B. ItwillthrowanerrorasBETWEENcanonlybeusedforNumbersandnotstrings.
C. Itwilldisplayalltheemployeeshavinglastnamesstartingfrom'B'andendingwith'E'.

D. Itwilldisplayalltheemployeeshavinglastnamesintherangeofstartingalphabetsas'B'and'E'
excludingthenamesstartingwith'B'and'E'.
Answer:A.TheBETWEENoperatorworkswiththerangeofcharactervaluesalso.
40.Whatwillbetheoutcomeofthequerymentionedbelow?
SELECTemployee_id,last_name,first_name,salary,manager_id
FROMemployees
WHEREmanager_idIN(200,100,300);

ORDERBYmanager_idASC
A. ItwillshowalltheemployeeswhoareunderthemanagershavingIDsintherangestartingfrom
100to300.
B. ItwillshowalltheemployeeswhoareunderthemanagershavingIDs100,200or300.
C. ItwillthrowanerrorasthemanagerIDsshouldbeputinquotes.
D. Itwillthrowanerrorasthesortingofmanager_idintheWHEREclauseconflictswiththe
ORDERBYclause.
Answer:B.TheINoperatorcanbeusedtoprovidesmallandlimitednumberofrange.
41.WhichofthefollowingclausedefinesaMembershipcondition?
A. BETWEEN
B. LIKE
C. ISNULL
D. INN OT I N
Answer:D.TheINoperatordefinesaMembershipconditionwhichmayusearangeofvaluesora
subquery.
42.WhichofthefollowingdatatypescanbeusedwithinINoperator?
A. VARCHAR2
B. NUMBER
C. DATE
D. ALL
Answer:D.TheINoperatorworkswithalltypesofvalues.
43.Youneedtodisplaythelistofalltheemployeeswhosefirstnamestartswith
BryanorJason.Whichofthefollowingquerieswillfulfilltherequirement?
. SELECTemp_id,last_name,first_nameFROMemployeesWHEREfirst_nameLIKE
'Bryan%'ORfirst_nameLIKE'Jason%';

. SELECTemp_id,last_name,first_nameFROMemployeesWHEREfirst_nameBETWEEN
'Bryan'and'Jason';

. SELECTemp_id,last_name,first_nameFROMemployeesWHEREfirst_nameIN('Bryan',
'Jason');

. SELECTemp_id,last_name,first_nameFROMemployeesWHEREfirst_name='Bryan'OR
first_name='Jason'

Answer:C,D.TheINoperatorchecksforANYvaluesdefinedasmembershipcondition.
44.Youneedtoextractdetailsofthosedepartmentswhosenamecontainsthestring
'_DXX'.WhichofthebelowWHEREclausescouldbeusedintheSELECTstatementto
gettherequiredoutput?
A. WHEREdept_idLIKE'%_DXX%'ESCAPE'_'
B. WHEREdept_idLIKE'%\_DXX%'ESCAPE'\'
C. WHEREdept_idLIKE'%_D123%'ESCAPE'%_'
D. WHEREdept_idLIKE'%\_D123%'ESCAPE'\_'
Answer:B.
45.WhichstatementistrueregardingthedefaultbehavioroftheORDERBYclause?
A. Inacharactersort,thevaluesarecasesensitive.
B. NULLvaluesarenotconsideredatallbythesortoperation.
C. OnlythosecolumnsthatarespecifiedintheSELECTlistcanbeusedintheORDERBYclause.
D. Numericvaluesaredisplayedfromthemaximumtotheminimumvalueiftheyhavedecimal
positions.
Answer:A.TheORDERBYclausedoesacasesensitivesortingwithcharactervalues.
46.YouneedtogenerateareportofallemployeesfromtheEMPLOYEEStablebasedon
thefollowingconditions:1.TheEmployeefirstnameshouldnotbeginwith'T'or'N'.2.
TheEmployee'ssalaryshouldbemorethan20000.3.TheEmployeeshouldhavebeen
hiredafter1stJanuary2010.WhichWHEREclausewouldgivetherequiredresult?
A. WHEREfirst_nameNOTLIKE'T%'ORfirst_nameNOTLIKE'N%'ANDsalary>20000AND
hire_date>'1JAN10'
B. WHEREf irst

n ameN OT

LI K E T

ORsalary>20000ORhire_date>'1JAN10'

C. WHEREfirst_nameNOTLIKE'T%'ANDfirst_nameNOTLIKE'N%'ANDsalary>20000AND
hire_date>'1JAN10'
D. WHEREf irst

n ameN OT

LI K E

ANDsalary > 20000AN Dhire

d ate

>

1 J AN 10

Answer:C.
47.UsingtheEMPLOYEEStable,youneedtodisplaythenamesofallemployeeshired
afterJanuary1,2013,startingwiththefreshers.Whichquerywouldgivetherequired
result? C hooseallthatapply.

. SELECTfirst_name,hire_dateFROMemployeesWHEREhire_date>'01JAN13'ORDER
BY2DESC;

. SELECTfirst_name,hire_dateFROMemployeesWHEREhire_date>'01JAN13'ORDER
BYfirst_nameDESC;

. SELECTfirst_name,hire_dateFROMemployeesWHEREhire_date>'01JAN13'ORDER
BY1DESC;

. SELECTfirst_name,hire_date"STARTDATE"FROMemployeesWHEREhire_date>'01
JAN13'ORDERBY"STARTDATE"DESC;

Answer:A,D.
48.UsingtheEMPLOYEEStable,youneedtofindoutthenamesandsalariesofallthe
employeeshiredindepartments100and101inthetimeinterval15thMarch'12to15th
October'13.Whichtwoquerieswouldgivetherequiredresult? C hoosetwo.
. SELECTfirst_name,salaryFROMemployeesWHEREdept_idIN(100,101)ANDhire_date
BETWEEN'15MAR12'AND'15OCT12';

. SELECTfirst_name,salaryFROMemployeesWHEREdept_id=100ORdept_id=101AND
hire_date>='15MAR12'ORhire_date<='15OCT12';

. SELECTfirst_name,salaryFROMemployeesWHERE(dept_idBETWEEN100AND101)AND
(hire_dateIN('15MAR12','15OCT12'));

. SELECTfirst_name,salaryFROMemployeesWHERE(dept_id=100ORdept_id=101)
AND(hire_date>='15MAR12'ANDhire_date<='15OCT12');

Answer:A,D.
49.UsingtheEMPLOYEEStable,youissuethefollowingquerytogeneratethenames,
currentsalaryandthesalaryincreasedafteranappraisalby25%.Theincreasedsalary
foralltheemployeesshouldbeabove30000.
SELECTfirst_name,salary,
salary+(salary*0.25)"INCREASED_SALARY"
FROMemployees
WHEREincreased_salary>30000;

ThequerythrowsanerrorORA00904.Whatisthereasonfortheerror?
A. TheparenthesisismissingintheexpressionusedinSELECTstatement.
B. Singlequotesmustbeusedtodefineacolumnalias.
C. ColumnaliascannotbeusedintheWHEREclause.
D. ColumnaliasintheWHEREclausemustbeenclosedwithindoublequotationmarks.
Answer:C.AcolumnaliascannotbeusedinWHEREclauseconditionsbutcanbeusedinSELECT

statementandORDERBYclause.
50.YouneedtodisplayemployeenamesfromtheEMPLOYEEStablethatbelongtothe
Departmentid100withminimumsalaryaseither2000or4000andnojob_id.You
issuethefollowingquery.
SELECTfirst_name,dept_id,salary
FROMemployees
WHEREdept_id=100AND(salary=2000ORsalary=4000)
ANDjob_id<>'';

Whichstatementistrueregardingtheabovequery?
A. Itexecutessuccessfullybutreturnsnoresult.
B. Itexecutessuccessfullyandreturnstherequiredresult.
C. Itgeneratesanerrorbecausetheconditionspecifiedforjob_idisnotvalid.
D. Itgeneratesanerrorbecausetheconditionspecifiedforthesalarycolumnisnotvalid.
Answer:A.Theconditionsalary = 2000ORsalary = 4000 resultsinFALSEbecauseanemployee
cannotheldmultiplesalariesatatime.
51.WhichthreetaskscanbeperformedusingSQLfunctionsbuiltintoOracleDatabase?
C hoosethree.

A. Displayingadateinanondefaultformat
B. Findingthenumberofcharactersinanexpression
C. Substitutingacharacterstringinatextexpressionwithaspecifiedstring
D. Combiningmorethantwocolumnsorexpressionsintoasinglecolumnintheoutput
Answer:A,B,C.UseformattingfunctionsT O
LEN GT H , REP LAC E toachievetheobjectives.

C H AR,

T O D AT E

,andcharacterfunctions

52.YouneedtogenerateareportthatdisplaystheIDsofallemployeesinthe
EMPLOYEEStablewhosesalaryisatleast25%morethanthevalue20000.Thedetails
shouldbedisplayedinthedescendingorderofthesalary.Youissuethefollowing
query.
SELECTemp_id
FROMemployees
WHEREsalary>=20000*0.25
ORDERBYsalary*0.25DESC;

Whichstatementistrueregardingtheabovequery?
A. Itexecutesandproducestherequiredresult.
B. ItproducesanerrorbecauseanexpressioncannotbeusedintheORDERBYclause.
C. ItproducesanerrorbecausetheDESCoptioncannotbeusedwithanexpressionintheORDER
BYclause.

D. ItproducesanerrorbecausetheexpressionintheORDERBYclauseshouldalsobespecifiedin
theSELECTclause.
Answer:A.TheORDERBYclausecancontaincolumnexpressions.
53.ExaminethestructureanddataoftheTRAININGStable:
NameNull?Type

TRAINING_IDNOTNULLNUMBER(5)
TRAINING_LOCATIONNUMBER(7,2)
START_DATEDATE
END_DATEDATE
TRAINING_IDSTART_DATETRAINING_COST

11
01JAN10

1000
22

01FEB10

2000
33

01MAR10

3000

DatesarestoredinthedefaultdateformatddmonrrintheTRAININGStable.Which
threeSQLstatementswouldexecutesuccessfully? C hoosethree.
. SELECTstart_date+'10'FROMtrainings;
. SELECT*FROMtrainingsWHEREstart_date='010110';
. SELECTtraining_costFROMtrainingsWHEREtraining_id>'11';
. SELECT*FROMtrainingsWHEREstart_date='01JANUARY10';
Answer:A,C,D.
54.Whichofthefollowingstatementsis/aretruewithrespecttothebelowquery?
SELECTemp_id,first_name
FROMemployees
ORDERBYdept_id;

A. ORDERBYclauseshouldcontainonlythosecolumnswhichareintheSELECTstatement.
B. Theabovequerywillsorttheresultsetindescendingorder.
C. ORDERBYclausecancontainanycolumnintherelatedtable,notnecessarilythecolumnsinthe
SELECTstatement.
D. Itthrowsanerroronexecution.
Answer:C.TheORDERBYclausecanuseacolumntosortthedatawhichisnotselectedinthe
columnlistbutiscontainedinthetableusedinFROMclause.
55.WhichfeatureofORDERBYclauseisdemonstratedinthebelowquery?

SELECTemp_id,first_nameEmpName
FROMemployees
ORDERBY"EmpName";

A. ORDERBYclauseshouldcontainonlythosecolumnswhichareintheSELECTstatement.
B. Theabovequerywillsorttheresultsetindescendingorderoffirstnamesofemployees.
C. ORDERBYclauseworkswithcolumnaliases.
D. TheSELECTquerythrowsanerroronexecutionbecausecolumnaliascannotbeusedinORDER
BYclause.
Answer:C.TheORDERBYclausesworksfinewiththecolumnaliasesusedinSELECTstatement.
56.Whatistrueaboutthequerygivenbelow?
SELECTlast_name,job_id,department_id,hire_date
FROMemployees
ORDERBY2;

A. ItexecutessuccessfullysortingthequeryresultsbasedontheJOB_ID.
B. TheORDERBYclausecannotcontainanumeric.
C. TheORDERBYclausewillnotfunctionasnoneofthecolumnsintheSELECTstatementare
usedintheORDERBYclause.
D. Thequerythrowsanerroronexecution.
Answer:A.NumericpositionofthecolumncanbeusedintheORDERBYclause.
57.Youneedtolisttheemployeesdetailsfordifferentjobsbutonlyoneatatime.
SELECTemp_id,first_name,last_nameFROMemployeesWHEREjob_id....;

WhichofthefollowingisaneasierwaytoachievethesameinSQL*Plus?
A. SubstituteeachJobIdatatime
B. Use*tolistdetailsofallemployees
C. Use&JOBtopromptforuserinputeverytimethequeryisexecuted
D. DeclaresessionvariablestosubstituteJobIdvaluesinthequery
Answer:C.The&Xnotationhaultsthequeryexecutionandpromptsforuserinputeverytimethe
queryisexecuted.
58.WhichofthefollowingstatementsistrueregardingsubstitutionvariablesinSQL?
A. Thesamequerycanbeexecutedfordifferentvaluesusingthesubstitutionvariables.
B. Usingthesubstitutionvariables,oneneedstoaltertheWHEREclauseeverytime.
C. SubstitutionvariablesarenotsupportedinOracle.
D. Thereisalimitationthatavalueissupposedtobeenteredinthesubstitutionvariablesevery

timeduringtheexecutionofaquery.
Answer:A.
59.WhichofthefollowingdatatypeisassignedtoSubstitutionvariables?
A. VARCHAR2
B. DATE
C. NODATATYPE
D. NUMBER
Answer:C.Substitutionvariablesdonothavethedatatypeoftheirownbutcomplywiththe
column'sdatatypewithwhomtheyareused.
60.Whichamongthefollowingistrueaboutsubstitutionvariables?
A. Thevalueenteredinthevariablesremainsconstantandtheusercannotchangethevaluesafter
theexecutionofthequeryforthefirsttime.
B. Thevalueisstoredinthevariablesafterthequeryexecutesonce.
C. ThesubstitutionvariablesonlysupportNUMBERS.
D. Thevaluestoredinthesubstitutionvariablesusingasingleampersand isusedforthefirst
executionandgetsdiscarded.
Answer:D.
61.WhichofthefollowingisacorrectsyntaxforSubstitutionvariablesinSQL*Plus?
A. :var
B. $var
C. &var
D. &&var
Answer:C,D.
62.WhichofthefollowingSubstitutionvariableswilltaketheenteredvalueonceand
thenkeepsitfortherestofthesession?
A. &&var
B. &var
C. :var
D. ::var
Answer:A.Asubstitutionvariablewithdoubleampersandrepeatedlyusesthevalueonceprovided
bytheuser.
63.Whichofthefollowingistrueaboutsubstitutionvariables?
A. OnlyNUMBERScanbeenteredasvalues.

B. OnlyCharacterstringscanbeenteredasvalues.
C. BothNumbersandCharacterscanbeenteredasvalues.
D. Noneoftheabove.
Answer:C.
64.Whatistrueaboutthequerygivenbelow?
SELECTfirst_name,last_name,employee_id,salary
FROMemployees
WHEREemployee_id=&eid;

A. Itthrowsanerror"ORA00904:"&eid":invalididentifier"
B. Itexecutessuccessfully.
C. TheWHEREclausecan'thavesubstitutionvariables.
D. Thequerypromptsforavaluetobeenteredforthevariable&eidandexecutessuccessfully
takingavalidvalueofemployee_id.
Answer:B,D.
65.Choosethestatementswhichholdtrueaboutthequerygivenbelow.
SELECTfirst_name,last_name,&&prompt_col
FROMemployees
ORDERBY&&promp_col;

A. Itthrowsanerrorastheuseofthesubstitutionvariableprompt_colisnotallowed.
B. Itexecutessuccessfullybuttheresultsetisnotsorted.
C. ItexecutessuccessfullybutthevariablevalueenteredintheSELECTstatementisignored.
D. Itexecutessuccessfullyandthevalueofthesubstitutionvariableismaintainedthroughoutthe
session.
Answer:D.AsubstitutionvariablecanbeusedinalltheclausesofSQLquery.
66.Whichofthefollowingcommandsisusedtocreateandassignavaluetoa
substitutionvariableinSQL*Plus?
A. &var
B. &&var
C. SET
D. DEFINE
Answer:D.UseDEFINEcommandinSQL*Plustodeclareasubstitutionvariableinasession.
67.WhatwillbetheoutcomeofthebelowactivityinSQL*Plus?
DEFINEeid=117

SELECTfirst_name,last_name,employee_id,salary
FROMemployees
WHEREemployee_id=&eid;

A. TheSELECTquerythrowserrorassubstitutionvariablescannotbedefinedinthesession.
B. Itpromptstheusertoenterthevalueforthevariable&eid.
C. ItexecutessuccessfullywiththeemployeeIDsubstitutedas117.
D. ItignorestheDEFINEcommandbecausethesubstitutionvariableisdeclaredwithout
ampersand & sign.
Answer:C.
68.Whatisthecommandtoremovethevalueofthesubstitutionvariablesetbythe
commandDEFINE?
A. UNDEFINE
B. SETOFF
C. DELETE
D. CLEAR
Answer:A.UseUNDEFINEcommandtodeleteasubstitutionvariablefromthesession
69.Whichofthefollowingcommandsisusedtocheckthesubstitutionvariablesvalues
beforeandafterexecutionofanSQLquery?
A. DEFINE
B. UNDEFINE
C. SHOWVARIABLE
D. VERIFY
Answer:D.UseVERIFYcommandinSQL*PlusandSQLDevelopertocheckthesubstitutionofvalues
usingsubstitutionvariables.
70.WhichofthefollowingarevalidoperatorsfortheWHEREclause?
A. >=
B. ISNULL
C. !=
D. ISLIKE
Answer:A,B,C.
71.Evaluatethefollowingquery:
SELECTename||q'{'ssalaryis}'||sal
AS"Salary"

FROMemp;

Whathappenswhentheabovequeryisexecuted?
A. Givesanerrorbecausebracescannotbeusedwith[q]operator
B. Giveserrorduetodatatypemismatch
C. Executessuccessfullyandaddsanapostrophe s attheendofeachemployee'sname

D. Executessuccessfullyandappendstheemployeenamewiththeliteral"{'sstartdatewas}"
Answer:C.
72.WhichofthebelowWHEREclausepredicateswillcorrectlylisttheemployeesfrom
department20?
A. WHEREdeptnoIS20
B. WHEREdeptno20
C. WHEREdeptno=20
D. WHERE20=deptno
Answer:C,D.Theequalityoperator= isusedtocomparetheoperandsintheconditionforequality.
73.WriteaSELECTquerytolisttheemployeeswhosesalaryisgreaterthan1000.
. SELECTename,salFROMempWHEREsalGREATERTHAN1000
. SELECTename,salFROmempWHEREsal>1000
. SELECTename,salFROMempWHEREsal>=1000
. SELECTename,salFROMempWHEREsalMORETHAN1000
Answer:B.Thegreaterthanoperator> isusedtocomparetheoperandsinthecondition.
74.WhatwouldhappenwhenthebelowqueryisexecutedinSQL*Plus?
SELECTename,sal,deptno
FROMemp
WHEREsal/10>deptno*10;

A. Executessuccessfullyandliststheemployeeswhose10thpartofsalaryisgreaterthan10times
hisdepartmentnumber
B. Raiseserrorbecauseexpressionsmustbeenclosedwithparentheses
C. RaiseserrorbecauseWHEREclausecannotevaluateexpressions
D. RaiseserrorbecauseWHEREclausecannotuseliterals
Answer:A.TheWHEREclausecancontainexpressions.

75.DeterminetheerrorinthebelowSELECTstatement
SELECTename,deptno,sal
FROMemp
WHEREjob=CLERK;

A. WHEREclausecannotreferthecolumnJOBsinceitdoesn'tappearsintheSELECTcolumnlist
B. CharacterliteralCLERKmustbeenclosedwithinsinglequotes
C. CharacterliteralCLERKmustbeenclosedwithinparentheses
D. Noerrorinthequery
Answer:B.Characterliteralsmustbeenclosedwithinsinglequotes
76.InterprettheoutputofthebelowSQLquery
SELECTename,deptno,sal
FROMemp
WHEREsysdatehiredate>100;

A. Thequeryliststheemployeeswhosehiredateisatleast100daysearlierthanthecurrentdate
B. Thequeryliststheemployeeswhohaveworkedmorethan100daysinthecompany
C. Thequeryliststheemployeeswhosehiredateisafter100daysinthatyear
D. Thequeryliststheemployeeswhohavespentlessthan100daysinthecompany
Answer:A,B.DatesexpressionscanbeusedinWHEREclause
77.Whichofthefollowingquerywilldisplaytheemployeeswhicharehiredafter31st
Decemeber,1982?
. SELECTename,deptnoFROMempWHEREhiredate>'31DEC1982';
. SELECTename,deptnoFROMempWHEREhiredate>to_date('31DEC1982','DDMM
YYYY');

. SELECTename,deptnoFROMempWHEREhiredate>to_char('31DEC1982','DDMM
YYYY');

. SELECTename,deptnoFROMempWHEREhiredate>31DEC1982;
Answer:A,B.Dateliteralsmustbeenclosedwithinsinglequotes.
78.WhichofthefollowingWHEREconditionswilllistemployeeswhowerehiredon
currentdate?
A. WHEREsysdatehiredate=0
B. WHEREsysdate=hiredate
C. WHEREsysdatehiredate<1

D. WHEREto_datesysdate,
hiredate =

DD M ON Y Y Y Y

DD M ON Y Y Y Y

=to_date

Answer:C,D.TheconditionSYSDATE=HIREDATEwillnotworkbecauseSYSDATEcontains
dynamictimestampcomponentwhilehiredateisastaticvalueinthedatabase.
79.Whatofthefollowingarethevalidformatsofdateliteralswhichcanbeusedin
WHEREclause?
A. 24/Mar/95
B. 02121983
C. 19JUN2001
D. 31.04.2010
Answer:A,C.DefaultformatfordateliteralsisDDMONRR.

Vous aimerez peut-être aussi