You are on page 1of 16

Practice Q & A

(Chapter 1 - 7)

Chapter 1
1.
A RDBMS groups data in a logical manner into tables and manages the access to the tables. Yes No A table always has columns and rows. No Yes A schema diagram is used to understand a database!s design. No Yes A column in a table de#ined as N$% N&'' is a primary or #oreign (ey. No Yes Re#erential integrity is en#orced by the relationship between the primary (ey and #oreign (ey. Yes No

2.

".

).

Additional *+A #or ,hapters 1-./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age 1 o# 16 7ersion8 )9292334

Answers for "Chapter 1"


Yes A RDBMS groups data in a logical manner into tables and manages the access to the tables.

1.

2.

No

A table always has columns and rows. Note: A table can exist without rows but must have at least one column.

3.

Yes

A schema diagram is used to understand a database s design.

4.

No

A column in a table de!ined as N"# N$%% is a primary or !oreign &ey.

5.

Yes

Re!erential integrity is en!orced by the relationship between primary &ey and !oreign &ey.

,hapter 2
1.
Any column in a table is a candidate #or the S:':,% list. Yes No

2.

%he (eywords D;S%;N,% and &N;*&: cannot be used interchangeably in a S:':,% list. No Yes %he D:S,R;B: command is a S*' command. No Yes <iles sa=ed with a .s>l e?tension can be e?ecuted with the @ command.
Additional *+A #or ,hapters 1-./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age 2 o# 16 7ersion8 )9292334

".

Yes No

).

%he push pin icon in S*' De=eloper allows you to toggle between the wor(sheets. Yes No %he S*'A0lus bu##er shows the last S*' command you typed. No Yes An $racle database re>uires that a user ha=e a user id and password to communicate with it. Yes No You can store at most "C333 characters in a 7AR,1AR2 column. Yes No You must always type column and table names in lowercase letters #or the S*' statement to e?ecute correctly. Yes No

6.

..

B.

4.

Answers for "Chapter 2"


1.
Yes Any column in a table is a candidate !or the S'%'(# list.

2.

No

#hese &eywords D)S#)N(# and $N)*$' cannot be be used interchangeably.

3.

No

#he D'S(R)B' command is a S*% command.

4.

Yes

+iles saved with a .s,l extension can be executed with the command.

5.

No

#he push pin icon in S*% Developer allows you to toggle between the wor&sheets.

Additional *+A #or ,hapters 1-./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age o# 16 7ersion8 )9292334

6.

Yes

#he S*%./lus bu!!er shows the last S*% command you typed.

7.

Yes

An "racle database re,uires that a user have a user id and password to communicate with it.

8.

Yes

0ou can store at most 12333 characters in a 4AR(5AR6 column.


Note. #his answer is ("RR'(#2 unless you use an "racle version 7 or below where the limit was 62333 characters.

9.

No

0ou must always type column and table names in lowercase letters !or the S*% statement to execute correctly.
Note: #he S*% language s &eywords are not case8sensitive. +or clarity and readability you !ollow a naming convention. #he convention used in this boo& is listed in Appendix B2 9S*% +ormatting :uidelines.9

,hapter
1.
%he B:%D::N operator tests #or a range o# =alues. Yes No

2.

;t is not possible to limit the number o# rows returned #rom a S:':,% statement. No Yes You can test #or null =alues by using an empty string such as the #ollowing8 SELECT * FROM course WHERE prerequisite = ''. No Yes %he optional (eyword AS can precede the alias name. Yes No %he AND and $R logical operators can only be combined with the use o# parentheses.
Additional *+A #or ,hapters 1-./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age " o# 16 7ersion8 )9292334

".

).

Yes No

6.

%he $RD:R BY clause must #ollow the D1:R: clause. No Yes %he #ollowing notation starts a multi-line comment. 9A Yes No A pseudocolumn such as R$DN&M is not actually stored in the database. Yes No %he underscore wildcard character can match multiple characters. Yes No

..

B.

4.

Answers for "Chapter 3"


1.
Yes #he B'#;''N "/'RA#"R tests !or a range o! values.

2.

No

)t is not possible to limit the number o! rows returned !rom a S'%'(# statement. Note: #he ;5'R' clause allows you to restrict the number o! rows returned by the ,uery.

3.

No

0ou can test !or null values by using an empty such as the !ollowing:

SELECT * FROM course WHERE prerequisite = ''

4.

Yes

#he optional &eyword AS can precede the alias name.

5.

No

#he AND and "R logical operators can only be combined with the use o! parentheses.

6.

Yes

#he "RD'R B0 clause must !ollow the ;5'R' clause.

Additional *+A #or ,hapters 1-./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age ) o# 16 7ersion8 )9292334

7.

Yes

#he !ollowing notation starts a multi8line comment. <.

8.

Yes

A pseudocolumn such as R";N$M is not actually stored in the database.

9.

No

#he = underscore wildcard character can match multiple characters.

,hapter "
1.
,haracter #unctions trans#orm data in tables in order to retrie=e it more easily. Yes No You can retrie=e speci#ic character data in a database regardless o# what case it was entered in. Yes No Arithmetic operators and number #unctions can be combined. No Yes %he D&A' table contains data trans#ormed by character #unctions. No Yes 'i(e character #unctionsC number #unctions operate on single =alues. Yes No %he '0AD #unction le#t trims a string. Yes No &nli(e many other character #unctionsC the ':NE%1 and ;NS%R #unction return a N&MB:R.
Additional *+A #or ,hapters 1-./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age 6 o# 16 7ersion8 )9292334

2.

".

).

6.

..

No Yes

B.

%he #ollowing S*' >uery returns -18 S:':,% S;EN2-")5 <R$M dual Yes No You can substitute the N7' #unction with the ,$A':S,: #unction. No Yes %he simple ,AS: e?pression tests #or e>uality only. Yes No

4.

13 .

Answers for "Chapter 4"


1.
No (haracter !unctions trans!orm data in tables in order to retrieve it more easily.

Note: All !unctions2 including character !unctions2 trans!orm the output o! data2 not actual data in tables. 0ou learn about modi!ying the data in tables in (hapter >>2 9)nsert2 $pdate2 and Delete.9

2. 3. 4. 5.

Yes

0ou can retrieve speci!ic character data in a database regardless o! what case it was entered in. Arithmetic operators and number !unctions can be combined.

Yes

No

#he D$A% table contains data trans!ormed by character !unctions.

Yes

%i&e character !unctions2 number !unctions operate on single values.

6. 7. 8.

No

#he %/AD !unction le!t trims a string.

Yes

$nli&e many other character !unctions2 the %'N:#5 and )NS#R !unction return a N$MB'R. #he !ollowing S*% ,uery returns 8>: S'%'(# S):N?81@A +R"M dual

Yes

Additional *+A #or ,hapters 1-./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age . o# 16 7ersion8 )9292334

9. 10.

Yes

0ou can substitute the N4% !unction with the ("A%'S(' !unction.

Yes

#he simple (AS' expression tests !or e,uality only.

,hapter )
1.
%he #ollowing S*' >uery implicitly per#orms a data type con=ersion.
SELECT student_id, last_na e FROM student WHERE student_id = '!"#'

No Yes

2.

Dhat is the result o# the #ollowing S*' >ueryF


SELECT TO_$%M&ER''(&C') FROM dual

$racle :rror message AB, 12

Dhich o# the #ollowing S*' statements results in this error8 $RA-31.228 in=alid number F
SELECT FROM SELECT FROM SELECT FROM SELECT FROM TO_CH(R'TO_$%M&ER'*+++,+++)) dual TO_CH(R'TO_$%M&ER''-*+++,+++')) dual TO_$%M&ER'TO_CH(R'+++,+++)) dual TO_CH(R'TO_$%M&ER''*+++,+++')) dual

".

Dhich #ormat mas( is re>uired to display this outputF !Mar 1.C 2313! Mon-dd yyyy Mon ddC yyyy dd-mon-yyyy M$N ddC YY

).

Dhich #ormat mas( is re>uired to display this outputF !Sunday 291B92313!F


Additional *+A #or ,hapters 1-./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age B o# 16 7ersion8 )9292334

<mDay mm9dd9yyyy DAY MM9DD9YYYY Day mm9dd9yyyy Day#m MM9DD9YYYY

6.

Does the #ollowing S*' statement return any rowsF


SELECT * FROM section WHERE start_date_ti e &ETWEE$ TO_.(TE''#!*.EC*""//','..*MO$ 0000') ($. TO_.(TE''/!1/!1!+//','MM1..10000')

;n=alid >uery. Yes No

..

Dould you change the #ollowing S*' statement in any wayF


SELECT start_date_ti e FROM section WHERE TO_CH(R'start_date_ti e, '..*MO$*0000') 2 '/!*3($*"/!/'

No Yes

B.

Dill the #ollowing S*' statement return an errorF


SELECT course_no, odi4ied_date FROM section WHERE odi4ied_date = '""*M(R*++'

No Yes

4.

%he #ollowing shows one o# the de#ault #ormats #or the %;M:S%AM0 D;%1 %;M: G$N: data type. !DD-M$N-RR 11.M;.SS.<< AM %G18%GM!. Yes No %he %$HDS;N%:R7A' #unction con=erts a te?t literal to an ;N%:R7A' DAY %$ S:,$ND data type. No Yes

13.

Answers for "Chapter 5"


1.
Yes #he !ollowing S*% ,uery implicitly per!orms a data type conversion.

SELECT student_id, last_na e


Additional *+A #or ,hapters 1-./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age 4 o# 16 7ersion8 )9292334

FROM student WHERE student_id = '!"#'


#he S#$D'N#B)D column is o! the N$MB'R data type. #he ;5'R' clause speci!ies the text literal >6C which is a string2 also called a text constant or text literal. #he two data types do not agree2 there!ore2 "racle per!orms an implicit conversion. )t is always pre!erable to explicitly per!orm the conversion.

2.

Oracle error message

;hat is the result o! the !ollowing S*% ,ueryD

SELECT TO_$%M&ER''(&C') FROM dual

A text literal such as AB( cannot be converted into a number.

3.

;hich o! the !ollowing S*% statements results in this error: "RA8 3>766: invalid number SELECT TO_CH(R'TO_$%M&ER''-*+++,+++')) FROM dual
A text literal such as E8FFF.FF cannot be converted into a number. $se the S$BS#R !unction to remove the E symbol2 and then convert to a number.

4. 5.

Mon dd, yyyy

;hich !ollowing !ormat mas& is re,uired to display this outputD Mar >72 63>3 ;hich !ormat mas& is re,uired to display this outputD Sunday 6<>G<63>3
#he !illmode ?!mA speci!ier is re,uired be!ore the Day !ormat mas&. Note the case o! the !m speci!ier is irrelevant.

m!ay mm"dd"yyyy

6.

No

Does the !ollowing S*% statement return any rowsD

SELECT * FROM section WHERE start_date_ti e &ETWEE$ TO_.(TE''#!*.EC*""//','..*MO$ 0000') ($. TO_.(TE''/!1/!1!+//','MM1..10000')
#he B'#;''N operator re,uires the lowest end o! the range !irst2 then the highest. )nstead2 write it as !ollows:

SELECT * FROM section WHERE start_date_ti e &ETWEE$ TO_.(TE''/!1/!1!+//','MM1..10000') ($. TO_.(TE''#!*.EC*""//','..*MO$*0000')

7.

Yes

;ould you change the !ollowing S*% statement in any wayD

SELECT start_date_ti e FROM section WHERE TO_CH(R'start_date_ti e, '..*MO$*0000') 2 '/!* 3($*"/!/'


Do not use the #"B(5AR !unction on the S#AR#BDA#'B#)M' column2 because the ,uery returns the incorrect result.

8.

No

;ill the !ollowing S*% statement return an errorD


Additional *+A #or ,hapters 1-./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age 13 o# 16 7ersion8 )9292334

SELECT course_no, odi4ied_date FROM section WHERE odi4ied_date = '""*M(R*++'


#his ,uery does not result in an error. But there are two ways to improve the ,uery. +irstly2 the text literal 668MAR8FF relies on implicit conversion to the DA#' data type and does not speci!y the !ormat mas&. )! this statement is executed on a system with a di!!erent de!ault !ormat mas&2 it results in an error. Secondly2 it does not speci!y the century in the text literal. %astly2 always consider the time component. #he ,uery could be improved as !ollows:

SELECT course_no, odi4ied_date FROM section WHERE odi4ied_date 5=TO_.(TE''""*M(R*!+++', '..* MO$*0000') ($. odi4ied_date 2 TO_.(TE''"#*M(R*!+++', '..* MO$*0000')

9. 10.

Yes

#he !ollowing shows one o! the de!ault !ormats !or the #)M'S#AM/ ;)#5 #)M' H"N' data type. DD8M"N8RR 55.M).SS.++ AM #H5:#HM . #he #"BDS)N#'R4A% !unction converts a text literal to an )N#'R4A% DA0 #" S'("ND data type.

Yes

,hapter 6
1.
Aggregate #unctions always return a single result #or a group o# =alues. No Yes Aggregate #unctions usually ignore N&'' =alues. No Yes

2.

An aggregate #unction can be used in a 1A7;NE clause. Yes No %he 1A7;NE clause can be used instead o# the D1:R: clause. Yes No %he M;N and MAI #unctions wor( only on the N&MB:R data type. No Yes %he #ollowing >uery is in=alid.
SELECT (67'CO(LESCE'cost, /))
Additional *+A #or ,hapters 1-./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age 11 o# 16 7ersion8 )9292334

".

).

6.

FROM course

Yes No

..

%he #ollowing >uery is in=alid.


SELECT S0S.(TE, 'HELLO', student_id, CO%$T'*) FROM enroll ent 7RO%8 &0 student_id

Yes No

Additional *+A #or ,hapters 1-./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age 12 o# 16 7ersion8 )9292334

Answers for "Chapter #"


1.
Yes Aggregate !unctions always return a single result !or a group o! values.

2.

Yes

Aggregate !unctions usually ignore N$%% values.


#he exception is ("$N#?.A2 which does ta&e N$%% values into account.

3. 4. 5. 6.

Yes

An aggregate !unction can be used in a 5A4)N: clause.

Yes

#he 5A4)N: clause can be used instead o! the ;5'R' clause.

No

#he M)N and MAI !unctions wor& only on the N$MB'R data type.

No

#he !ollowing ,uery is invalid.

SELECT (67'CO(LESCE'cost, /)) FROM course


No #he !ollowing ,uery is invalid.

7.

SELECT S0S.(TE, 'HELLO', student_id, CO%$T'*) FROM enroll ent 7RO%8 &0 student_id

Additional *+A #or ,hapters 1-./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age 1 o# 16 7ersion8 )9292334

,hapter .
1.
Dhich >uestion is answered by the #ollowing S*' statementF
SELECT FROM WHERE ($. ($. description, section_no, last_na e course c, section s, instructor i c,course_no = s,course_no s,instructor_id = i,instructor_id TO_CH(R'start_date_ti e, '.0') = 'T%E'

Show a list o# the coursesC sectionsC and instructors. Display the course descriptionC section numberC and the last name o# the instructor that teaches the section. Show only those courses with enrollments starting on %uesdays. Display a list o# course descriptionsC their section numbersC and #or each section the last name o# the assigned instructor. $nly show sections that start on %uesdays Display the course descriptionC section numberC and last names o# instructors teaching classes on Dednesdays. %he #ollowing two S*' statements are e>ui=alent.
SELECT FROM WHERE ($. SELECT FROM O$ WHERE s,student_id, e,section_id, s,last_na e student s, enroll ent e s,student_id = e,student_id last_na e = 'Torres' s,student_id, section_id, last_na e student s 3O9$ enroll ent e 's,student_id = e,student_id) last_na e = 'Torres'

2.

Yes No

Determine the >uestion #or the #ollowing S:':,% statement.


SELECT FROM WHERE ($. ($. ($. ($. ($. c,description, :rade_t;pe_code, nu eric_:rade :rade :, enroll ent e, section s, course c c,course_no = ##/ :,student_id = ""! s,course_no = c,course_no s,section_id = e,section_id :,section_id = e,section_id :,student_id = e,student_id

Show the course description o# the course 3 in which the student with the id 221 is enrolled. Show also the grade type. Show the descriptionC grade typeC and grade #or course number 3 and the student with the id o# 221. ;n=alid >uery. %he S:':,% statement causes a ,artesian product.
Additional *+A #or ,hapters 1-./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age 1" o# 16 7ersion8 )9292334

".

Determine the >uestion #or the #ollowing S*' statement.


SELECT FROM O$ WHERE <,*, last_na e, 4irst_na e student s 3O9$ <ipcode < 's,<ip = <,<ip) last_na e = 'Torres'

Show students with the #irst and last name o# %orres and their corresponding Jip code. ;nclude all the columns o# the G;0,$D: table in the result. ;n=alid >uery. Show the #irst and last name o# students with the last name o# %orres.

Answers for "Chapter $"


1.
;hich ,uestion is answered by the !ollowing S*% statementD

SELECT FROM WHERE ($. ($.

description, section_no, last_na e course c, section s, instructor i c,course_no = s,course_no s,instructor_id = i,instructor_id TO_CH(R'start_date_ti e, '.0') = 'T%E'

Display a list o! course descriptions2 their section numbers2 and !or each section the last name o! the assigned instructor. "nly show sections that start on #uesdays

2.

Yes

#he !ollowing two S*% statements are e,uivalent.

SELECT FROM WHERE ($. SELECT FROM O$ WHERE

s,student_id, e,section_id, s,last_na e student s, enroll ent e s,student_id = e,student_id last_na e = 'Torres' s,student_id, section_id, last_na e student s 3O9$ enroll ent e 's,student_id = e,student_id) last_na e = 'Torres'

#he statements are e,uivalent. )t is pre!erable to speci!y aliases in the column2 because it is easier to identi!y which tables the columns belong to. )t also avoids any errors in S*% statements i! a column with the same name is added to the other table in the !uture.

3.

Determine the ,uestion !or the !ollowing S'%'(# statement.

SELECT FROM WHERE ($. ($. ($. ($. ($.

c,description, :rade_t;pe_code, nu eric_:rade :rade :, enroll ent e, section s, course c c,course_no = ##/ :,student_id = ""! s,course_no = c,course_no s,section_id = e,section_id :,section_id = e,section_id :,student_id = e,student_id

Additional *+A #or ,hapters 1-./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age 1) o# 16 7ersion8 )9292334

Show the description2 grade type2 and grade !or course number CC3 and the student with the id o! 66>.

4.

Determine the ,uestion !or the !ollowing S*% statement.

SELECT FROM O$ WHERE

Show the !irst and last name o! students with the last name o! #orres and their corresponding Jip code. )nclude all the columns o! the H)/("D' table in the result.

<,*, last_na e, 4irst_na e student s 3O9$ <ipcode < 's,<ip = <,<ip) last_na e = 'Torres'

Additional *+A #or ,hapters 1-./ Oracle SQL by Example by Alice Rischert/ 0rentice 1all 223345 0age 16 o# 16 7ersion8 )9292334

You might also like